1. Write a program to display multiplication table of a given number using for loop.
Answers
Explanation:
for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
Algorithm
Given below is an algorithm to print multiplication table by using for loop in C language −
Step 1: Enter a number to print table at runtime.
Step 2: Read that number from keyboard.
Step 3: Using for loop print number*I 10 times.
// for(i=1; i<=10; i++)
Step 4: Print num*I 10 times where i=0 to 10.
Example
Following is the C program for printing a multiplication table for a given number −
Live Demo
#include <stdio.h>int main(){
int i, num;
/* Input a number to print table */
printf("Enter number to print table: ");
scanf("%d", &num);
for(i=1; i<=10; i++){
printf("%d * %d = %d\n", num, i, (num*i));
}
return 0;}
Output
When the above program is executed, it produces the following result −
Enter number to print table: 7
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70
Answer:
7
14
21
28
35
42
49
56
63
70
Explanation:
These are a answer to the question and line wise