我想打印 if else 语句。较大的else if正在执行,但a[i]==0未执行。怎么处理?
#include <stdio.h>
#include <stdlib.h>
int main(){
int nl, i, j, count=0;
printf("Enter the number of values: ");
scanf("%d",&nl);
int a[nl];
for(i=0; i<nl; i++){
printf("Enter the number: ");
scanf("%d", &a[i]);
if (a[i]<nl){
printf("Less than\n");
}
else if(a[i]>nl){
printf("Greater than\n");
}
else if(a[i]==0){
printf("Equal\n");
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是一个逻辑缺陷。a[i]==0应该是a[i]==nl。或者你可以只写else {.