Here we are going to write program to check enter number is even or odd . We have to know about operator used in C which is most important for applying condition in the program . On the previous blog I told you about operator used in C so please read from there . For writing program to check number is even or odd. As we know that even number are those number which are exactly divisible by 2 and odd number are those which are not divisible by 2. Now we are going to write program.
/*program to check no.is even or odd*/
#include <stdio.h>
void main()
{
int a;
clrscr ();
printf ("/n Enter a number:");
scanf ("%d", & a);
if ( a%2==0)
printf ("/n a is even number:");
else
printf ("/n a is odd number :");
getch();
}
From written program you seen that first of all we have to enter a number from the user and then we have used condition for checking. A even number is divisible by 2 then it must gives 0 as remainder then print number is even otherwise it will we odd number. Please comment for any issue in this program for spreading information.
/*program to check no.is even or odd*/
#include <stdio.h>
void main()
{
int a;
clrscr ();
printf ("/n Enter a number:");
scanf ("%d", & a);
if ( a%2==0)
printf ("/n a is even number:");
else
printf ("/n a is odd number :");
getch();
}
From written program you seen that first of all we have to enter a number from the user and then we have used condition for checking. A even number is divisible by 2 then it must gives 0 as remainder then print number is even otherwise it will we odd number. Please comment for any issue in this program for spreading information.
No comments:
Post a Comment