Home30 Days Of CodeHackerrank Day 5 : loops 30 days of code solution

# Hackerrank Day 5 : loops 30 days of code solution

In this Hackerrank Day 5 : loops 30 days of code solutionn.

Given an integer,n, print its first 10 multiples. Each multiple n * i (where 1<=i<=10) should be printed on a new line in the form: n x i = result.

#### Input Format

A single integer, n.

#### Constraints

``2<=n<=20``

#### Output Format

Print 10 lines of output; each line i(where 1<=i<=10) contains the result of n * i in the form: n x i = result.

#### Sample Input

``2``

#### Sample Output

``````2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20``````

For Loop Syntax

### Code Explanation

Here n is an integer number we have to print the table of n, first take user input and store the value in ‘n‘. after that use a ‘for loop‘ and put the three condition in ‘for loop‘. Below is a for loop syntax.

So according to above syntax take a user input, and initialize the loop with i = 0 and put the condition i <= 10 and last condition is i++ or i =i+1.And multiplication i and n and print the result is according to the problem statement.

``````for(initialization ; condition ; increament / decreament)
{
---
---
Executable statements
---
---
}``````

Below is the Solution in all majors 3 language, C, C++, and Java. So according to choice go through the solutions and try to understand the code. If you feel any difficulty comment below or contact us on our social media profiles.

# Hackerrank Day 5 : loops 30 days of code solution

## Loops HackerRank Solution in C

``````#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
int N,i;
scanf("%d",&N);
if(N>=2 && N<= 20){
for(i=1;i<=10;i++){
printf("%d x %d = %d \n",N,i,(N*i));
}
}
return 0;
}``````

## Loops HackerRank Solution in C ++

```#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main(){
int N;
cin >> N;
for (int i=1;i<=10;i++){
cout<<N<<" x "<<i<<" = "<<N*i<<endl;
}
return 0;
}```

## Loops HackerRank Solution in Java

```import java.io.*;
import java.util.*;

public class Solution {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1;i<11;i++){
int ans = n * i;
System.out.println(n + " x " + i + " = " + ans);
}
}
}```

## Loops HackerRank Solution in Python 3

```#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
n = int(input())

for i in range(1,11):
s = n * i
print(n,"x",i,"=",s)```

## Loops HackerRank Solution in JavaScript

```process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
input_stdin += data;
});

process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});

return input_stdin_array[input_currentline++];
}

function printdis(N)
{
var i, temp;
for (i = 1; i <= 10; i++)
{
temp = N * i;
console.log(N + " x " + i + " = " + temp);
}
}

/////////////// ignore above this line ////////////////////

function main() {
printdis(N);

}```

NEXT : Hackerrank Day 6 : Let’s Review 30 days of code solution

30 Days of Code HackerRank Solutions List – Day 0 to Day 29

RELATED ARTICLES