In this HackerRank Conditional statements in c programming solution Given a positive integer denoting n, do the following:

  1. If 1 <= n <= 9, print the lowercase English word corresponding to the number (e.g., one for 1, two for 2, etc.).
  2. If n > 9, print Greater than 9.


HackerRank Conditional Statements in c solution


HackerRank Conditional statements in c programming problem solution.

#include<stdio.h>
#include<string.h>
int main()
{
 int n;
 scanf("%d",&n);
  char *a[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
  if(n<=9)
  {
     printf("%s",a[n]);
  }

 else
 {
     printf("Greater than 9");
 }
 return 0;
}


Second solution

#include <stdio.h>

int main()
{
    int n; 
    scanf("%d",&n);
    // Your code goes here.
    if (n == 1) {
        printf("one\n");
    } else if (n == 2) {
        printf("two\n");
    } else if (n == 3) {
        printf("three\n");
    } else if (n == 4) {
        printf("four\n");
    } else if (n == 5) {
        printf("five\n");
    } else if (n == 6) {
        printf("six\n");
    } else if (n == 7) {
        printf("seven\n");
    } else if (n == 8) {
        printf("eight\n");
    } else if (n == 9) {
        printf("nine\n");
    } else {
        printf("Greater than 9\n");
    }
     
    
    return 0;
}