vendredi 19 février 2021

Displaying high odd and even number in C

trying to get odd and even number to show, with larger numbers, It works fine with 8 nr but when ever i go over 9 it looks weird, the nr i typ in changes.

Ex with 8 nr:

Enter the ID : 20202020
20202020 is even.
Program ended with exit code: 0

But when doing it with 10 nr it looks like this:

Enter an integer: 2345678915
-1949288381 is odd.
Program ended with exit code: 0
// these nr that are different, what are they? 
//Have not found any info about it either... 

Code--

#include <stdio.h>

int main() 
{ 

    int id;
    printf("Enter the Id: ");
    scanf("%d", &id);

    if(id % 2 == 0)
        printf("%d is even.\n", id);
    else
        printf("%d is odd.\n", id);
    return 0;
}

I tried changing it to double, does not help.

does it have anything to do if

 if(id % 2 == 0)

what am I missing??

Aucun commentaire:

Enregistrer un commentaire