coder18s,blogspot.com

Powered by Blogger.

7.For Loop in C Hackerrank Solution

Task

For each integer  in the interval  (given as input) :

  • If , then print the English representation of it in lowercase. That is "one" for , "two" for , and so on.
  • Else if  and it is an even number, then print "even".
  • Else if  and it is an odd number, then print "odd".

Sample Input

8
11

Sample Output

eight
nine
even
odd
                 Program Code
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() 
{   
    int a, b;
    scanf("%d\n%d", &a, &b);
   
    char *str[] = {"one""two""three""four""five""six""seven",  "eight""nine"};
    
    for (int i=a; i<=b; i++)// i= 8 
    {
            if (i <= 9
        {
                printf ("%s\n", str[i-1]);
        }
            else if(i%2==0)
        {
                printf ("even\n");
        }
        else 
        {
            printf("odd\n");
        }
    }
    
    return 0;
}