我正在尝试查看 4x4 矩阵是否是对称的,以下是我目前所拥有的。编译后我收到消息:
pExam3p2.c:12:13: warning: expression result unused [-Wunused-value]
if (Num[r,c]==Num[c,r]){
^
pExam3p2.c:12:23: warning: expression result unused [-Wunused-value]
if (Num[r,c]==Num[c,r]).
我认为添加一个 else 语句可以解决这个问题。但事实并非如此。非常感谢任何想法。谢谢!
#include <stdio.h>
char isSymm (int Num[][4], int rows, int cols){
int r,c, count=0;
for (r=0; r<rows; r++){
for (c=0; c<cols; c++){
if (Num[r,c]==Num[c,r]){
count=count+1;
}
else{
count=count;
}
}
}
if (count==16){
return 'y';
}
else {
return 'n';
}
}
int main (void){
int Num[4][4];
int c;
int r;
int size =4;
for (r=0;r<size; r++){
for (c=0; c<size; c++){
printf("Enter your number: ");
scanf("%d", &Num[r][c]); //NOTE THE &...
}
}
char result= isSymm(Num, 4, 4);
printf("%c", result);
}