Blogger templates

Pages

Tuesday, 17 April 2012

C Program: Enter a Number and Determine It Is Even or Odd Number

C program image

This program is based on conditional statement that is if-else.
Write a Program: Enter a Number and Determine wheather it is Even or Odd Number.

#include<stdio.h>                          
// Header file contain input output functions.
#include<conio.h>                         
// Header file contain clrscr() and getch() functions.
void main()                                   
// C program execution start with this main function. No C program can execute without this main function.
{
int a,b;                                         
// Declare two variables a and b of integer data type.
clrscr();                                       
// Clear the result of previous output.
 
printf(" Enter the value of a");     
// This is output function. Enter the value of a is show on screen.
scanf("%d", &a);                     
// This is input fuction. We enter the value of variable a with the help of scanf function.
b=a%2;                                   
// The remainder value obtained after dividing integer variable a by 2 is assign to integer variable b.
if(b==0) 
// if-else condition is applied
{
printf("Number is Even");
}
else
{
printf("Number is Odd");
}
getch();
}
// If the condition b==0 is True then Number is Even execute other wise Number is Odd is executed. 

NOTE: The Lines written in // symbol is for just telling about the meaning of statement. These lines not executed in the program.
Output1:

Output1:
Enter the value of a           
44
Number is Even

Output2:
Enter the value of a              // clrscr() clears the previous output1
77
Number is Odd

0 comments:

Post a Comment