Code For Alls..!

get the code!!

Tuesday 19 September 2017

Day 5: Loops-hackerrank-solution

                                               Day 5: Loops-hackerrank-solution
Day 5: Loops-hackerrank-solution
Task
Given an integer, , print its first  multiples. Each multiple  (where ) should be printed on a new line in the form: n x i = result.
Input Format
A single integer, .
Constraints
  •  2<=n<=20
Output Format
Print 10 lines of output; each line  (where 1<=i<=10) contains the n x i of  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

C code:

#include <stdio.h>
int main(){
    int N,i; 
    scanf("%d",&N);
    for(i=1;i<=10;i++)
    printf("%d x %d = %d\n",N,i,N*i);
    return 0;
}



1 comment:

  1. for loop will work for 11 time which is not expected.The question is to print only 10 lines without the termination code i.e.i<=10

    ReplyDelete