HackerRank C- For Loop in C




For each integer n in the interval [a,b] (given as input) :

If 1<=n<=9, then print the English representation of it in lowercase. That is "one" for 1, "two" for 1 , 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 <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. int main()
  6. {
  7. int a, b;
  8. int n=0;
  9. scanf("%d\n%d", &a, &b);
  10. for(n=a;n<=b;n++)
  11. {
  12. if(n==1)
  13. {
  14. printf("one\n");
  15. }
  16. if(n==2)
  17. {
  18. printf("two\n");
  19. }
  20. if(n==3)
  21. {
  22. printf("three\n");
  23. }
  24. if(n==4)
  25. {
  26. printf("four\n");
  27. }
  28. if(n==5)
  29. {
  30. printf("five\n");
  31. }
  32. if(n==6)
  33. {
  34. printf("six\n");
  35. }
  36. if(n==7)
  37. {
  38. printf("seven\n");
  39. }
  40. if(n==8)
  41. {
  42. printf("eight\n");
  43. }
  44. if(n==9)
  45. {
  46. printf("nine\n");
  47. }
  48. if(n>9)
  49. {
  50. if(n%2==0)
  51. {
  52. printf("even\n");
  53. }
  54. else {
  55. printf("odd\n");
  56. }
  57. }
  58. }
  59. return 0;
  60. }




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