一个判断对角线上数据是否为1的方法, int k = identity_matrix(array,12);问题是:k = ?
#include<stdio.h>int array[12][12];
int
identity_matrix(int const array[][10],int const counts);
int
main(void)
{
int i;
for(i = 0;i<12;i++)
array[i][i] = 1;
int k = identity_matrix(array,12);
printf("%d\n",k);
}
int
identity_matrix(int const array[][10],int const counts)
{
int i,j;
for( i = 0;i<counts;i++)
{
for( j = 0 ;j<counts;j++)
{
if(i == j)
{
if(array[i][j] != 1)
return 0;
}else
{
if(array[i][j] !=0)
return 0;
}
}
}
return 1;
}