C++ conditional statement Hacker rank solution.
Task:
Given a positive integer "n" do the followings.
a) if 0<= n <= 9 . Then print the lowercase english word corresponding to the number. Ex: One for 1, Two for 2...
b). If n>9 . Then print "Greater than 9";
program for this:-
int main(){
int n;
cin>>n;
string num[10]={"Greater than 9", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
if(n>9){
cout<< num[0];
}
else{
cout<<num[n];
}
return 0;
}
Comments
Post a Comment