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