Tuesday, 26 March 2019

C Program to check whether a number is even or odd

This program demonstrates the functioning of if else statements. Program asks user for an integer number and gives the output whether number is even or odd.
An integer is even if it is divisible by 2 meaning if by dividing number by 2, remainder is zero, then number is even otherwise it is an odd number.
//C Program to demonstrate the functioning of if else statements
//check if number is divisible by 2. If it is, then number is even otherwise it is odd number
#include <stdio.h>
int main()
{
    int num;
    printf("Enter an integer: ");
    scanf("%d", &num);
    if(num % 2 == 0)
        printf("%d is even number.\n", num);
    else
        printf("%d is odd number.\n", num);
    return 0;
}
Output:



Please comment if you find anything incorrect, or you want to improve the topic discussed above.

No comments:

Post a Comment