Input Format
A single integer denoting .
Constraints
Output Format
If , then print the lowercase English word corresponding to the number (e.g., one for two for , etc.); otherwise, print Greater than 9 instead.

hackerrank conditional statement problem solution in c++ programming

Conditional Statements problem solution in C++ programming | HackerRank

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    
    int n;
    cin >> n;
    if(n == 1) {
        cout << "one";
    }
    else if(n == 2) {
        cout << "two";
    }
    else if(n == 3) {
        cout << "three";
    }
    else if(n == 4) {
        cout << "four";
    }
    else if(n == 5) {
        cout << "five";
    }
    else if(n == 6) {
        cout << "six";
    }
    else if(n == 7) {
        cout << "seven";
    }
    else if(n == 8) {
        cout << "eight";
    }
    else if(n == 9) {
        cout << "nine";
    }
    else {
        cout << "Greater than 9";
    }
    
    return 0;
}

Second solution

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {

    int n;
    string represent[10] = {"Greater than 9", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    cin >> n;

    if(n > 9) {
        cout << represent[0];
    }
    else {
        cout << represent[n];
    }

    return 0;
}