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

Popular posts from this blog

Allocate Book Problem Solution || Code Studio

Peak Index in a Mountain Array || Binary Search practice example || Leet Code poblem #852

First and Last position of an element in sorted array | Binary Search Practice Example | Code Studio Interview Question