HackerRank C++ Conditional Statements




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



  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <deque>
  7. #include <queue>
  8. #include <stack>
  9. #include <string>
  10. #include <bitset>
  11. #include <cstdio>
  12. #include <limits>
  13. #include <vector>
  14. #include <climits>
  15. #include <cstring>
  16. #include <cstdlib>
  17. #include <fstream>
  18. #include <numeric>
  19. #include <sstream>
  20. #include <iostream>
  21. #include <algorithm>
  22. #include <unordered_map>
  23. using namespace std;
  24. int main()
  25. {
  26. int n;
  27. cin >> n;
  28. string num[10] = {"Greater than 9", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
  29. cin >> n;
  30. if(n > 9)
  31. {
  32. cout << num[0];
  33. }
  34. else
  35. {
  36. cout << num[n];
  37. }
  38. return 0;
  39. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube