Day 5 Loops Hackerrank Solution | 30 Days of Code Solution

We have to find the day 5 loops hackerrank solution in C programming language. This is a part of 30 days of code hackerrank programming challenge. So we are going to solve this programming challenge with full logic, code explanations, and syntax. Before going to actual programming challenge, let's find out what we have and what we have to do to solve hackerrank day 5 solution in c programming or Hackerrank Loops Solution, and another programming as well.

Day 5 Loops Hackerrank Solution

Day 5 Loops Hackerrank Solution
So we have the following day 5 loops hackerrank programming challenge.


In this challenge, we're going to use loops to help us do some simple math. Get the Hackerrank Day 5 Solution in C programming.


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.



Output Format

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

Sample Input


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

Day 5 Loops Hackerrank Statements

We want to clear one thing here we do not have any rights to programming challenges, but the day 5 loops hackerrank solution belongs to us. The original programming statement belongs to the hackerrank. We do not claim and authority to the programming problem statement. This is just for educational purposes. We copied the hackerrank programming problem statement in this article. All the rights reserved by the Hackerank website. Let's find out Hackerrank Loops Solution in C.

Day 5 For Loop in C Hackerrank Solution Logic

Day 5 FOR Loop in C Hackerrank Solution Logic, We can take a FOR Loop and put the condition in the loop to print the table. This is a straightforward program. We need to use only one FOR Loop for this problem. This programming can be solved using 'While Loop' or 'While Do Loop' and 'Do-While Loop.' So why wait, let's find out Hackerrank Day 5 Solution in C programming language.

Explanation Hackerrank Day 5 Solution in C

Try to solve this problem using 'While Loop' and 'Do-While Loop.' 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 programming challenge statement.

Get the Solution in C++ and Java programming Language Click Here

You can practice and submit your loops hackerrank solution by clicking to this link- Click Here

Day 5 Loops Hackerrank Solution in C

Below find the For Loop in C Hackerrank Solution.

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

char* readline();

int main()
    char* n_endptr;
    char* n_str = readline();
    int n = strtol(n_str, &n_endptr, 10);

    if (n_endptr == n_str || *n_endptr != '\0') { exit(EXIT_FAILURE); }

    for (int i = 1; i <= 10; i++) 
        printf("%i x %i = %i\n", n, i, n * i);
    return 0;

char* readline() {
    size_t alloc_length = 1024;
    size_t data_length = 0;
    char* data = malloc(alloc_length);

    while (true) {
        char* cursor = data + data_length;
        char* line = fgets(cursor, alloc_length - data_length, stdin);

        if (!line) { break; }

        data_length += strlen(cursor);

        if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; }

        size_t new_length = alloc_length << 1;
        data = realloc(data, new_length);

        if (!data) { break; }

        alloc_length = new_length;

    if (data[data_length - 1] == '\n') {
        data[data_length - 1] = '\0';

    data = realloc(data, data_length);

    return data;

Hackerrank Loops Solution Output

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

For Loop Syntax

for(initialization ; condition ; increament / decreament)
Executable statements

The output of number 10.

This will print the table of any number let's take an example of number 10(10 is our input for this Hackerrank Loops Solution) then the output is below.

10 x 1 = 10
10 x 2 = 20
10 x 3 = 30
10 x 4 = 40
10 x 5 = 50
10 x 6 = 60
10 x 7 = 70
10 x 8 = 80
10 x 9 = 90
10 x 10 = 100

If you want to solution of 30 days of code solution(All solutions from day 0 to day 29, including day 5 loops hackerrank solution) from Day 0 please check the 30 Days of code solutions. You can also find more program below of this post.

For Loop in C Hackerrank Solution Output

Loops Hackerrank Solution Output
Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

1 comment:

  1. SIR, can't we solve it in simple .I solved this code in 5 lines instead using the long code. I am new to coding and I don't understand the purpose of this long code instead of the simple one.int main()
    int n,i,s;
    printf("%d x %d = %d\n",n,i,s);
    return 0;
    like this