Home > Back-end >  A two-dimensional array c language to solve the problem
A two-dimensional array c language to solve the problem

Time:12-26

Define a 2 d array of 3 * 4 and initialization, requirements: 1, find out which is an even number of elements, the output its position;

2, the output will be the sum of all the even,

CodePudding user response:

 int a [3] [4]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; 
Int I, j, sum=0;
For (I=0; I & lt; 3; I++)
{
For (j=0; J & lt; 4. J++)
{
If (a [I] [j] % 2==0)
{
The sum +=a, [I] [j].
Printf (" % d, % d \ n ", I, j);
}
}
}
Printf (" % d \ n ", sum);
  • Related