HackerRank C++ For Loop




For each integer n in the interval [a,b] :

If 1<=n<=9, then print the English representation of it in lowercase. That is "one" for 1 , "two" for 2 , and so on.
Else if n>9 and it is an even number, then print "even".
Else if n>9 and it is an odd number, then print "odd".



  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. int main()
  8. {
  9. int num1,num2;
  10. cin >> num1 >> num2;
  11. string Arr1[9] = {"one","two","three","four","five","six","seven","eight","nine"};
  12. for(int i =num1; i <= num2;i++)
  13. {
  14. if(i <= 9)
  15. {
  16. cout << Arr1[i-1] << endl;
  17. }
  18. else
  19. {
  20. if(i%2 ==0)
  21. {
  22. cout << "even" << endl;
  23. }
  24. else
  25. {
  26. cout << "odd" << endl;
  27. }
  28. }
  29. }
  30. return 0;
  31. }
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