(Even Numbers) Write a program that inputs a series of integers and passes them one at a time to function isEven, which uses the modulus operator to determine whether an integer is even. The function should take an integer argument and return true if the integer is even and false otherwise.
Solution:
Solution:
#include <iostream> using std::cout; using std::cin; using std::endl; #include <cstdio> bool even( int ); int i; int main() { cout << "Enter integer: "; cin >> i; while( i != EOF ) { cout << even( i ) << endl; cout << "Enter integer: "; cin >> i; } return 0; } //even function bool even( int i ) { if( i % 2 == 0 ) return true; else return false; }
Post A Comment:
0 comments: