Hacerrank C++ --- For Loop

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    // Complete the code.
    int a , b  , g ;
    cin>> a ;
    cin>> b ; 
    for ( g = a ; g<=b ; g++) {
        if(g==1){
            cout << "one" << endl;
        }
        else if(g==2) {
            cout << "two" << endl;
        }
        else if(g==3) {
            cout << "three" << endl;
        }
        else if(g==4) {
            cout << "four" << endl;
        }
        else if(g==5) {
            cout << "five" << endl;
        }
        else if(g==6) {
            cout << "six" << endl;
        }
        else if(g==7) {
            cout << "seven" << endl;
        }
        else if(g==8) {
            cout << "eight" << endl;
        }else if(g==9) {
            cout << "nine" << endl;
        }else if(g>9) {
              if(g%2==0){
                  cout << "even" << endl;
              }
              else{
                  cout <<"odd" << endl ; 
              }
            
        }


    }
    
    
    return 0;
}

Comments

Popular posts from this blog

Infosys - Monster RPG GAME Sample Question Solution

Hackerrank -- C++ - Variable Sized Array Solution