vendredi 27 septembre 2019

Why does C program give wrong output for positive integer?

The below program gives correct result for negative and zero integer, but for positive integer, it gives wrong output:

Enter the value of a : 6
The no is positive
The no is zero

Why?

int main()
{   int a;
    printf("Enter the value of a : ");
    scanf("%d",&a);
    if(a>0)
        printf("The no is positive\n");
    if(a<0)
        printf("The no is negative\n");
    else
       printf("The no is zero\n");
}

Aucun commentaire:

Enregistrer un commentaire