if else hackerrank c++ problem
Given a positive integer , do the following:
- If , print the lowercase English word corresponding to the number (e.g.,
onefor ,twofor , etc.). - If , print
Greater than 9.
Input Format
A single integer, .
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.
Program:
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string a[10]={"Greater than 9", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
cin>>n;
if(n>9){
cout<<a[0]<<endl;
}else if(0<n<=9){
cout<<a[n]<<endl;
}
return 0;
}
No comments:
Post a Comment