Mahesh has given a two-dimensional 3*3 array starting from A [0][0]. You should add the alternate elements of the array and print its sum. It should print two different numbers the first being sum of A 0 0, A 0 2, A 1 1, A 2 0, A 2 2 and A 0 1, A 1 0, A 1 2, A 2 1.
#include <stdio.h>
int main()
{ int A[3][3],i,j;
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
{scanf("%d ",&A[i][j]);}}
int m=0,n=0;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if((i+j)%2==0)
m=m+A[i][j];
else
n=n+A[i][j];}}
printf("%d\n%d",m,n);
return 0;
}
Comments
Post a Comment