Tuesday, January 15, 2019

C Program To Check Whether A Number Is Even Or Odd


Check Even Or Odd Number:-

What is odd or even number:-
If a number is completely divided by a number and  without giving remainder when dividing, then that number is called even number.
Example-   10/2  remainder 0
                 18/3  remainder 0
if a number is not completely divided by a number and without giving remainder when dividing, then number is called odd number. 
Example-   10/3  remainder 1
                 18/4  remainder 2
In this C program we checks whether a number is even or odd by using Arithmetic Modulus operator. here we take a variable of type int name as number for input a number from the user when program run. 
We check condition if(number%2==0) is true then execute if block otherwise execute else block.



   /*
      Program : Check Even Or Odd Number
      Filename : evenOdd.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
       int number;
       printf("Enter the number :");
       scanf("%d",&number);
           if(number%2==0)
             {
                  printf("%d is even number",number);            
             }
           else
             {               
                  printf("%d is odd number",number);
             }  
       return 0;
   } 

Output :


   Program Run First Time -
 
  Enter the number : 23
  23 is odd number

  Program Run Second Time -
 
  Enter the number : 6
  6 is even number






0 comments:

Welcome to you in All Coding Help