C program to check odd or even number


                        To find number is odd or even we use simple logic that if number is divide by 2 and reminder is 0 than is is even number else it is odd number. to find reminder in C we use %(Modulo) operator which return the reminder of the number for example if we divide 9 by 2 than reminder is 1.

C program to check number is odd or even.

#include<stdio.h>

void main()
{
       int no;
       clrscr();

       printf("Enter a number::");
       scanf("%d",&no);

       if((no%2)==0)
       {
              printf("No is even");
       }
       else
       {
              printf("No is odd");
       }
       getch();
}

c program to check odd or even number

In above example of c programming for checking odd or even number, first we getting a number from user as input. Than after it will check condition by if statement to determine that whether a number is odd or even.

For that it use % ( Modulo ) operator which return the remainder of number. In if condition it will use as no%2, it means it return the remainder. So, if the remainder is zero than it will execute the statement of if block. Otherwise its odd number and control transfer to the else part of the c program and it execute the statements which are in else part.

Download


0 comments:

Post a Comment