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.
// 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.
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 Response to "C Program: Enter a Number and Determine It Is Even or Odd Number"
Post a Comment