The program is written to display the multiplication table of a given number. The number is taken as input from the user. A for loop is used to display the multiplication table of the number.
For example, if the given number be 2, then the multiplication table will be:
2 × 1 = 2
2 × 2 = 4
2 × 3 = 6
2 × 4 = 8
2 × 5 = 10
2 × 6 = 12
2 × 7 = 14
2 × 8 = 16
2 × 9 = 18
2 × 10 = 20
INPUT: A number
OUTPUT: Multiplication Table of the given number
PROCESS:
Step 1: [Taking the input]
Read n [The number for which the multiplication table is to be calculated]
Step 2: [Calculating the Multiplication Table]
For i=1 to 10 repeat
Print n × i
[End of ‘for’ loop]
Step 3: Stop.
for(i=1;i<=10;i++)-----------------------------------------O(10)
{
printf("%d*%d=%d\n",n,i,n*i);
}
Here, the time complexity of this program is O(n) and the value of ‘n’ is 10.
The space complexity of this program is O(1) as it requires a constant number of memory spaces for any given input.