Search This Blog

Tuesday 28 June 2011

Odd or Even


 This is a simple program to illustrate the coding flow.

 Since all even numbers are divisible by 2 
 Algorithm:
           READ input into number
           IF MOD( number , 2 ) IS EQUAL TO ZERO THEN number IS even
           IF MOD( number , 2 ) IS NOT EQUAL TO ZERO THEN number IS odd.

Code Listing:

  1. int main()
  2. {
  3.     int n;
  4.     
  5.     printf ("Enter a number: ");
  6.     scanf ("%d",&n);
  7.  
  8.     if (n%2 ==0 ) {
  9.             printf ("The number is Even");
  10.     } else {
  11.             printf ("The number is Odd");
  12.     }

  13.    getch();
  14.    return 0;
  15.  
  16. }

No comments:

Post a Comment