Saturday, July 28, 2018

Example of check Even or Odd number


In this C program to check whether a number is Even or Odd.
In this example , if....else statement is used to check whether a number entered by the user is Even or Odd.

An even number is an integer that is exactly divisible by 2. Example: 0, 8, -24

An odd number is an integer that is not exactly divisible by 2. Example: 1, 7, -11, 15


#include <stdio.h>
int main()
{
    int number;

    printf("Enter an integer: ");
    scanf("%d", &number);

    if(number % 2 == 0)
        printf("%d is even.", number);
    else
        printf("%d is odd.", number);

    return 0;
}

Output:

No comments:

Post a Comment

C program for find square value

This is an example of how to find square value of a number using function.  #include<stdio.h> float square ( float x ); int ma...