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