cpp
Hackerrank C Tutorial for Loop Solution

HackerRank C tutorial for loop solution c++

Basic For Loop is a HackerRank problem from the Introduction subdomain of the C++ coding section. This article will explain how you can solve the HackerRank C tutorial for loop solution c++’ and present it stepwise for your more pleasing experience.

HackerRank C tutorial for loop solution

Problem statement

A for loop is a programming language statement that allows code to be repeatedly executed. The syntax is…

You can check out the complete problem on For Loop (opens in a new tab) at HackerRank.

Also Read: Variable sized Array problem on HackerRank solved

Solution

For Loop

#include <iostream>
#include <cstdio>
using namespace std;
 
int main() {
    int inp, inp2;
    cin >> inp;
    cin >> inp2;
 
    for ( int i=inp; i<=inp2; i++){
 
        if(i==1){
            cout << "one\n";
        }
        else if (i==2) {
            cout << "two\n";
        }
        else if(i ==3){
            cout << "three\n";
        }
        else if(i ==4){
            cout << "four\n";
        }
        else if (i==5) {
            cout << "five\n";
        }
        else if(i ==6){
            cout << "six\n";
        }
        else if(i ==7){
            cout << "seven\n";
        }
        else if (i==8) {
            cout << "eight\n";
        }
        else if(i ==9){
            cout << "nine\n";
        }
        else{
            if(i%2==0){
                cout << "even\n";
            }
            else {
                cout << "odd\n";
            }
        }
 
    }
 
    return 0;
}

IndGeek provides solutions in the software field, and is a hub for ultimate Tech Knowledge.