Coding Practice

Write a C program to check whether a number is even or odd

Check a number is even or odd
Sample Output
Enter a number: 21

This number is odd.

Process returned 0 (0x0)   execution time : 3.845 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    int num;
    
    printf("Enter a number: ");
    scanf("%d", &num);
 
    if(num % 2 == 0)
    {
        printf("\nThis number is even.\n");
    }
    else
    {
        printf("\nThis number is odd.\n");
    }
}
Sample Output
Enter a number: 36

This number is even.

Process returned 0 (0x0)   execution time : 5.251 s
Press any key to continue.

No comments:

Post a Comment

Change Theme
X