We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. C
  3. Conditionals and Loops
  4. For Loop in C
  5. Discussions

For Loop in C

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • mohmkad200
    3 months ago+ 1 comment

    I wanted to print it out like this printf("%s",a<=9?num[a-1]: a%2==0?"even\n":"odd\n" but it does not work, do you know why?

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    
    
    
    int main() 
    {
        int a, b;
        scanf("%d\n%d", &a, &b);
      	// Complete the code.
          char *num[]={"one","two","three","four","five","six","seven","eight","nine"};
        for(a;a<=b;a++)
        {
            if(a<=9)
                printf("%s\n", num[a-1]);
            else{
                if(a>9)
                    if(a%2==0)
                        printf("even\n");
                    else
                        printf("odd\n");
            }    
        }
    
        return 0;
    }
    
    -1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy