C Program to check even or odd.

 


C Program to check even or odd.



// Program to check entered integer is even or odd.

#include <stdio.h>
int main() {
    int n;
    printf("Enter an integer: ");
    scanf("%d", &n);

    //checks if the n is even.
    if(n%2==0) {
        printf("%d is even number.",n);
    }

    //checks if the n is odd.
    else {
        printf("%d is odd number.",n);
    }

    return 0;
}

Output

Enter an integer: 23
23 is a odd number.


Explanation

  • If test expression becomes true : statement inside if get executed and else statement get skipped from execution.
  • If test expression becomes false : statement inside if get skipped from execution and else statement get executed.
  • Here when user enters 23, test expression n%2==0 becomes false.Hence else statement get executed. 

Comments

Popular posts from this blog

ATM solution in C language.- Codechef

MOTIVATION SOLUTION IN C LANGUAGE | CODECHEF | IMDB

APPLE AND ORANGE | HACKERRANK | PROBLEM SOLVING | SOLUTION IN C