Even or odd
isEven() takes an integer value as an input parameter and returns 1 in case if the given number is even and 0 in case if the given number is odd.
Code
#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
bool isEven(int num)
{
if(num%2==0)
return true;
else
return false;
}
int main()
{
cout<<isEven(1);cout<<endl;
cout<<isEven(2);cout<<endl;
cout<<isEven(3);cout<<endl;
cout<<isEven(4);cout<<endl;
cout<<isEven(5);cout<<endl;
cout<<isEven(6);cout<<endl;
cout<<isEven(7);cout<<endl;
cout<<isEven(8);cout<<endl;
_getche();
return 0;
}
Output
0
1
0
1
0
1
0
1
0 comments:
Post a Comment