Monday, January 31, 2011

Functions in C++

Hi guys!the program below tells whether a number entered by a user is odd or even.
It is a program by passing a value to a function..
If this program gives errors please let me know,i am ready to help any time..
May this program helps you alot!!


#include<iostream>
#include<conio.h>
void even(int);
void odd(int);
using namespace std;

main()
{
int number;
do
{
cout<<"enter a number to find even odd,and 0 to exit:";

cin>>number;
if (number==0)
{
              cout<<"EXIT"<<endl;
              }
              else
even(number);
}
while(number!=0);
getch();
}

void even(int i)
{
    int y;
    if (i%2==0)
    cout<<"Number is even"<<endl;
    else
    odd(i);
    
}

void odd(int j)
{
    if (j%2==1)
    cout<<"Number is odd"<<endl;
}

No comments:

Post a Comment