You're online now.

Hurray! you are online now.

Odd or Even C

The C program to check given number is odd or even takes one integer number value as input from the user, and check the given number using '%' operator and displayed the output on the console/terminal using pritf() function.

#include<stdio.h>
    
    	
    int main(){
    	int n;
    	print("Enter the number : ");
    	scanf("%d", &n);
    	
    // if n is coompletely divisible by 2 then prints even otherwise n is odd
    	if(n % 2 == 0){
    		print("Even");
    	}else{
    		print("Odd");
    	}
    	
    	return 0;
    }
  1. The program inclusion of the stdio.h standard input-output library header file.
  2. The main() function is defined.
  3. 'n' is declared.
  4. A message is displayed on the screen using the printf() function to prompt the user to enter the number.
  5. Check condition if n is divisible by 2 (n % 2 == 0) then print the output on the user screen "Even" otherwise print the output on the user screen "Odd".
  6. The return statement is ued to exit the program successfully.

Algorithm to check Odd or Even

  1. Start
  2. Take value from ther user and store into n variable.
  3. if (n % 2 == 0) print "Even"
  4. else print "Odd"
  5. Exit
🖤 0
Buy me coffee ☕

Comments

Oops!

No comments here...