# 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".

Conditions

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

Example:-

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.

Solution:-

#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];
}
else
{
cout << num[n];
}

return 0;
}

Output:

You May Like This:-

#### Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed