Wednesday, 21 September 2016

Accept two integers and check if number less than 9 print the "number" in string format else if number>9 print "even" or "odd" based on the number

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int a,b;
string num[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
cin >> a >> b;
for (int i = a; i <= b; ++i) {
    if (i > 9) {
        i % 2 == 0 ? cout << "even\n" : cout << "odd\n";
    } else {
        cout << num[i] << endl;
    }       
}   
return 0;
}

No comments:

Post a Comment