Wednesday 27 June 2012

c++ program to find whether the number is odd or even.



#include <iostream>
using namespace std;
int main ()
{   
int i;
   
// Prompt user for i and obtain integer.

  cout << "Please enter an integer"<< endl;
  cin >> i;



// determine if i is even or odd
  if ( i % 2== 0 )

 // if the i when divided by 2 has no remainder then it's even.

       cout << i << " is even "<<endl;
 
else 

      // the i is odd

       cout << i << " is odd " <<endl;

  return 0;
}

No comments:

Post a Comment