Need a project done?

C++ Programming Developer

Search This Blog

Function to test whether a given integer is Even or Odd


/*
Write  a program by defining a function "even_odd" to test whether a given integer is even or odd.
Pass the integer value as a argument to function.
*/

#include <iostream>
using namespace std;

void even_odd(int);

int main()
{
int Num;
cout<< "Number: "; cin>>Num;
even_odd(Num);

return 0;
}

void even_odd(int Num)
{
if ( 0 == Num%2 ) //or u can write if(Num%2 == 0).
cout<<Num<<" is Even" << endl;
else
cout<<Num<<" is Odd"  << endl;
}

2 comments:

  1. If i want to return a value from defintion to call function .
    Then what should i so.?

    ReplyDelete
  2. What will i do
    When i will return a value in dumction definition

    ReplyDelete

"Don't let anyone ever make you feel like you don't deserve what you want."