In: Computer Science
Using for loop . Input an integer and identify whether it's EVEN OR ODD ( without using modulo operator )
using only <iostream> . C++ programming
#include <iostream>
using namespace std;
// It will return true if n is even. Otherwise odd.
bool isEven(int n)
{
bool isEven = true;
if(n<0)
n=-n;
for (int i=1; i<=n; i++)
isEven = !isEven;
return isEven;
}
int main()
{
int n;
cout<<" Enter an integer:";
cin>>n;
isEven(n) ? cout << "Even" : cout << "Odd";
return 0;
}
Output: