| Home |
User Guide
|
DB Recovery
|
| Download |
| Documents |
| FAQ |
| Books |
| About Me |
| C Programs |
| Stats |
/*
Program# 13
date : 25-12-2008
Even number or Odd number
*/
#include <stdio.h>
main(){
int n,x;
printf("\nEnter a number : ");
scanf("%d",&n);
x=n%2;
if(x==0) // even number is a number which is divisible by 2
printf("\n%d : Even number\n",n);
else
printf("\n%d : Odd number\n",n);
}
output: Enter a number : 35 35 : Odd number |
Things to note:1.The sign of the remainder is always same as the sign of the numerator.
2. The modular division % operator returns the remainder on dividing one integer 35 with another integer.
3. It cannot be applied on float.
4. If the expression (x = = 0) evaluates to true means, the printf statement next to if will get printed, otherwise the statement after else will get printed.
if - else statement
if(condition)
true statement;
else
false statement;
If there are more than one statement, then it can be enclosed in curly braces { }
if(condition)
{
statement 1;
statement 2;
.
.
statement n;
}
else
{
statement 1;
statement 2;
.
.
statement n;
}
Powered by Open Source Programmers
|