A Program to print a multiplication table

Source Code:

#include<stdio.h>

int main()

{

int row, col, n, result;

printf(“Enter a Number: “);

scanf(“%d”,&n);

for(row=1;row<=n;row++){

for(col=1;col<=10;col++){

result=row*col;

printf(“%d “,result);

}

printf(“\n”);

}

return 0;

}

Explanation:

Here, we will see a multiplication table from 1 to n. we will take n as input. We use “row” variable to control outer loop and “col” variable to control inner loop of the nested loop. Multiplication result will be stored in the variable “result” by multiplying “row” and “col”. Output will be displayed in the inner loop. 

“row” value of Outer loop starts from 1 and it will go up to n with increasing by 1. At a time, “col” value of Inner loop always starts with 1 and ends with 10 by upon successful entry into inner loop, the value of col will increase by 1 each time after completion of statements execution. When the value of “col” reaches 11, it breaks the condition of inner loop and prints a new line and it goes back to the increment portion of outer loop and this process will continue until the value of row is greater than n.  

Sample Input:

Enter a Number: 3

Sample output:

1 2 3 4 5 6 7 8 9 10

2 4 6 8 10 14 16 18 20

3 6 9 12 15 18 21 24 27 30

Share

One thought on “A Program to print a multiplication table

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Lean Blog by Crimson Themes.