by聽CodeChum Admin
My friends are geeking out with this new device I invented. It checks if a number is even or odd! 馃く
Do you want to try it out?
Instructions:
Input
1. Integer n
2. N integer values
Output
Enter路n:路5
Enter路value路#1:路3
3路is路odd
Enter路value路#2:路6
6路is路even
Enter路value路#3:路4
4路is路even
Enter路value路#4:路1
1路is路odd
Enter路value路#5:路3
3路is路odd
#include <iostream>
#include <string>
using namespace std;
string OddOrEven(int val)
{
if (val % 2 == 0)
return "even";
else
return "odd";
}
int main()
{
int n;
cout << "Enter n: ";
cin >> n;
int val;
for (int i = 0; i < n; i++)
{
cout << "Enter value #" << i + 1 << ": ";
cin >> val;
cout << val << " is " << OddOrEven(val)<<endl;
}
}
Comments
Leave a comment