Thread: please help to find the mistake in the folllowing program.

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    12

    please help to find the mistake in the folllowing program.

    the actual program reads the 5 x5 array of integers.but to make some changes i have asked user to enter the value of multidimensional square array.

    and it prints the value of rows total

    O/P:

    Enter the size of x*x arrays: 2


    Enter row 1: 2 3

    Enter row 2: 4 5


    row totals: 5 9


    Code:
    #include<stdio.h>
    int main(void)
    {
    int n;
    
    
    printf("Enter the size of x*x arrays:");
    scanf("%d", &n);
    
    
    int a[n][n],row[n],i=0,m=0,z=1;
    
    
    
    
    
    
        for(i=0;i<n;i++)
        {
            printf("Enter row %d: \n", z++);
    
    
            for(m=0;m<n;m++)
            {
                scanf("%d", &a[i][m]);
            }
            printf("\n");
    
    
        }
    
    
    
    
        printf("Row totals:\n");
    
    
        for(i=0;i<n;i++)
        {
           for(m=0;m<n;m++)
           {
               row[i]=row[i]+a[i][m];
           }
    
    
        }
    
    
    
    
        for(i=0;i<n;i++)
        {
            printf("%d\t", row[i]);
        }
    return 0;
    }
    the o/p i get:

    Code:
    Enter the size of x*x arrays:2
    Enter row 1:
    2 3
    
    
    Enter row 2:
    4 5
    
    
    Row totals:
    5       4199509
    Process returned 0 (0x0)   execution time : 21.720 s
    Press any key to continue.
    i only get right value for row1 and not for the other rows .
    please help.thanks

  2. #2
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    373
    You need to initialise your "row" elements before you use them.
    Last edited by gemera; 04-22-2015 at 03:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sily mistake...cant find it!
    By brack in forum C Programming
    Replies: 2
    Last Post: 02-28-2011, 03:29 PM
  2. Find my mistake!
    By kacey in forum C Programming
    Replies: 4
    Last Post: 02-03-2011, 03:10 AM
  3. Find my mistake!
    By kacey in forum C Programming
    Replies: 2
    Last Post: 02-02-2011, 08:36 PM
  4. Can not find my mistake in this code?
    By BLG in forum C Programming
    Replies: 2
    Last Post: 09-04-2009, 04:19 PM
  5. Please help! - Who find mistake in the program??
    By nivek in forum C++ Programming
    Replies: 4
    Last Post: 01-06-2008, 01:28 AM