如何运行 a[i] == 0 语句?

0 c if-statement

我想打印 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)

Lun*_*din 5

这是一个逻辑缺陷。a[i]==0应该是a[i]==nl。或者你可以只写else {.

  • @RedMailers“不工作”是什么意思?您向程序提供什么输入以及它打印什么? (2认同)