#include <stdio.h>
void countcolumn(int a[10][10]){
int i,j,flag=0;
for(i=0;i<10;i++){
for(j=0;j<10;j++){
if(a[i][j]==1){
flag=flag+1;
}
}
}
printf("\n%d\n",flag);
}
int one[10][10]={0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0, 0, 0, 0,
0, 1, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0};
您必须传递每一行并计算行数。然后传递每一列并计数一列。
void countONE(int a[10][10]){
int i,j,counter=0;
for(i=0;i<10;i++){
for(j=0;j<10;j++){
if(a[i][j]==1)
counter++;
}
printf("Row %d have %d one values.\n",i,counter);
counter=0;
}
for(i=0;i<10;i++){
for(j=0;j<10;j++){
if(a[j][i]==1)
counter++;
}
printf("Column %d have %d one values.\n",i,counter);
counter=0;
}
}