C Program To Accept A Number And Determine Whether It Is Even Or Odd.

Q19. Write a program to accept a number and determine whether it is even or odd.

Solution:

#include<stdio.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

printf(“\n Enter a number: “);

scanf(“%d”,&a);

 

a%2==0?printf(“\n It is an even number.”) : printf(“\n It is an odd number.”);

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter a number: 7

 

It is an odd number.

 

CASE 2:

Enter a number: 6

 

It is an even number.

Leave a Reply

Your email address will not be published. Required fields are marked *