Hacker Rank solution for Conditional Statements In C++

Problem:- Hacker Rank Solution Program In C++ For " Conditional Statements " or Hacker Rank Solution Program In C++ For Conditional Statements or Conditional Statements solution hacker rank or Hacker rank solution for c++ domain or Hacker rank solution for Conditional Statements sub domain or Conditional Statements solution in c++ of hacker rank or introduction solutions hacker rank.

Check Here:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Logic:- So for this problem, we have to take a strong array and as per requirement size of the array is 10, then put a condition and take a user input if number is given by user is 1 to 9 then print that number in words and if the number is greater than 9 then program should print the number is greater than 9.  let take an example so we can easily understand the full problem easily. see the below explanation of the problem.

Explanation:- First declare the string array like below and size of array should be 10 cause our requirement is for only 10 indexes,

String Array

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

Now use the if else condition, if the number is greater than 9 it should print the message " Greater than 9 " and if the number is between 1 to 9 then print the number in words ex if the number is 5 then program will print "five".


 if(n > 9)
        cout << num[0]; // if number is greater than 9 so first index of array will we printed.
        cout << num[n]; // index message will be printed.


1. First User Enter number = 1

Output = first

2. Second User Enter number = 9

Output = nine 

3. Third User Enter number = 10

Output = Greater than 9

Optional Hint:- No need to use a huge number of the header file in the program this problem can be solved by using only one header file #include <iostream> or if you want to use only one header file you can use the Master Header file. Master header in C++ is #include<bits/stdc++.h> after adding this header file no need to add any other header file.

Also Check- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Submit your solution here:- Click here

Tip:- Try to solve this problem using Switch Case. Before copy the program I recommended please read this full article, this will help you to build your own logic. 


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main()
    int n;
    cin >> n;
    string num[10] = {"Greater than 9", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    cin >> n;

    if(n > 9)
        cout << num[0];
        cout << num[n];

    return 0;


Hacker Rank solution  for Conditional Statements

Hacker Rank solution  for Conditional Statements

You May Like This:-

1. Hacker Rank Solution for 30 Days of Code

2. Hacker Rank solution for Attribute Parser

3. Java Program For Find The Gross Salary Of An Employee

4. Hacker Rank Solution For Conditional Statements

5. Hacker Rank Solution For Mini-Max Sum

6. Hacker Rank Solution For Birthday Cake Candles

7. Geeksforgeeks Solution For " Sum of Middle Elements of two sorted arrays "

8. Java Program For Converting Temperature Celsius Into Fahrenheit

9. Geeksforgeeks Solution For " Two Repeated Elements "

10. Hacker Rank Solution For Virtual Functions
Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

1 comment:

  1. https://www.youtube.com/watch?v=iE77rU_CnVA&t=28s

    check my easy code here