For Loop in C – Hacker Rank Solution | HackerRank Programming Solutions | HackerRank C Solutions

Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank of Programming Language C . At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight you profile to the recruiters.

In this post, you will find the solution for For Loop in CHackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

C is one of the most widely used Programming Languages. it is basically used to build Operating System. C was developed by Dennis Ritchie in 1972. Below are some examples of C Programming which might you understanding the basics of C Programming.

Objective

In this challenge, you will learn the usage of the for loop, which is a programming language statement which allows code to be executed until a terminal condition is met. They can even repeat forever if the terminal condition is never met.

The syntax for the for loop is:

for ( <expression_1> ; <expression_2> ; <expression_3> )
    <statement>
  • expression_1 is used for intializing variables which are generally used for controlling the terminating flag for the loop.
  • expression_2 is used to check for the terminating condition. If this evaluates to false, then the loop is terminated.
  • expression_3 is generally used to update the flags/variables.

The following loop initializes  to 0, tests that  is less than 10, and increments  at every iteration. It will execute 10 times.

for(int i = 0; i < 10; i++) {
    ...
}

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".

Input Format

The first line contains an integer, .
The seond line contains an integer, .

Constraints

Output Format

Print the appropriate English representation,even, or odd, based on the conditions described in the 'task' section.

Note: 

Sample Input

8
11

Sample Output

eight
nine
even
odd
For Loop in C – Hacker Rank Solution
#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.
   // For Loop in C - Hacker Rank Solution START
   
    char *str[] = {"one", "two", "three", "four", "five", "six", "seven",  "eight",  "nine", "even", "odd"};

    scanf("%d\n%d", &a, &b);
    for (int i=a; i<=b; i++)// i= 8 
    {
            if (i <= 9) 
        {
                printf ("%s\n", str[i-1]);
        }
            else
        {
                printf ("%s\n", str[9+(i%2)]);
        }
        
    // For Loop in C - Hacker Rank Solution END
    
    }
    return 0;
}

Leave a Comment

Ads Blocker Image Powered by Code Help Pro
Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Refresh