cpp
Conditional Statements C Hackerrank Solution

Conditional statements C++ HackerRank solution

If else conditional statements are one of the important steps toward the logic building. They help you to execute condition-based output. This tutorial will help you with Conditional statements C++ HackerRank solution.

conditional statements c++ hackerrank solution

Problem statement

If and else are two of the most frequently used conditionals in the c or the C++, they enable you to execute zero or one conditional statement among many such dependent conditional statements. We use them in the following ways…

You can check out the complete problem on Conditional statements (opens in a new tab) at HackerRank.

Also Read: Hackerrank problem on for loop

Solution

This is one of the largest programs to be written at the amateur level as it insists to write multiple lines of code including else if statement. Each number is converted to its string version and later printed with Cout.

#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int inp;
    cin >> inp;
 
    if(inp==1){
        cout << "one";
    }
    else if (inp==2) {
        cout << "two";
    }
    else if(inp ==3){
        cout << "three";
    }
    else if(inp ==4){
        cout << "four";
    }
    else if (inp==5) {
        cout << "five";
    }
    else if(inp ==6){
        cout << "six";
    }
    else if(inp ==7){
        cout << "seven";
    }
    else if (inp==8) {
        cout << "eight";
    }
    else if(inp ==9){
        cout << "nine";
    }
    else{
        cout << "Greater than 9";
    }
 
    return 0;
}

IndGeek provides solutions in the software field, and is a hub for ultimate Tech Knowledge.