Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

HackerRank Conditional Statements in C solution

YASH PAL, 12 July 202416 January 2026

HackerRank Conditional Statements in c problem solution – In this tutorial, we are going to solve HackerRank conditional statements in the c problem or write a solution program. In this problem, we need to read the positive integer value and then we need to check if the value is greater than print the text “Greater than 9” Else we need to print the English word that corresponds to that value in lowercase like if value 1 then print the one in lowercase.

Objective

if and else are two of the most frequently used conditionals in C/C++, and they enable you to execute zero or one conditional statement among many such dependent conditional statements. We use them in the following ways:

Task

Given a positive integer denoting n, do the following:

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

Input Format

The first line contains a single integer, n.

Constraints

  • 1 <= n <= 109

Output Format

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

Solution explained in Video

HackerRank Conditional Statements in solution
HackerRank Conditional Statements in solution

Conditional Statements in C 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;
}

Explanation

In the above-given program first, we included the two header files stdio.h and string.h, after that we defined the main() function. inside the main function, we first defined the integer variable n and then using the scanf() function we read the user input value and stored it in the variable n.

after that, we defined an array named a with predefined values like zero, one, two, three, four, five, six, seven, eight, and nine. we used these values to get the corresponding English words of value from 0 to 9.

After that using the if condition we checked if the value was less than or equal to 9 then using the printf() function we printed the corresponding English word from the array. else we printed the “Greater than 9” text on the output screen.

Next problem solution – HackerRank Foor Loop in C problem solution

C Solutions coding problems solutions Hackerrank Problems Solutions cHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

HackerRank C Solutions
Hello world in c solution
Playing with characters problem solution
sum and difference of two numbers problem solution
functions in c problem solution
pointers in c problem solution
Conditional statements in c problem solution
For loop in c solution
Sum of Digits of a five-digit number problem solution
Bitwise operators problem solution
Printing pattern using loops problem solution
1D Arrays in c problem solution
Array Reversal problem solution
Printing Tokens problem solution
Digit Frequency problem solution
Dynamic Array in c problem solution
Calculate the Nth term problem solution
Students Marks sum problem solution
Sorting Array of strings problem solution
Permutations of strings problem solution
Variadic functions in c problem solution
Querying the documents problem solution
Boxes through a tunnel problem solution
Small Triangles, Large Triangles problem solution
post-transition problem solution
Structuring the document problem solution

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes