The for loop is used to generate the multiplication table of a number entered by the user. The program accepts a number from the user and repeats the multiplication process from 1 to 10. Each iteration calculates and displays the multiplication result.
How It Works?
k and no.
k = 1 in the for loop.
k <= 10.
k.
k by 1 and repeat the process.
#include <stdio.h> #include <conio.h> main() { int k, no; clrscr(); printf( "\n Enter any no" ); scanf( "%d", &no); for (k = 1; k <= 10; k = k + 1) { printf ( "\n %d * %d = %d", no, k, no * k); } getch (); }
for loop to accept a number from the user and display its multiplication table from 1 to 20.for loop for repeated calculations and generate multiplication tables.no and k. Accept a number from the user. Use a for loop with condition k <= 20 and display the multiplication result using no * k.#include <stdio.h> #include <conio.h> main() { int k, no; clrscr(); printf ( "\n Enter any no" ); scanf ( "%d", &no); for (k = 1; k <= 20; k = k + 1) { printf ( "\n %d * %d = %d", no, k, no * k); } getch (); }
for loop to generate its multiplication table. The loop starts from 1 and continues until 20. In each iteration, the number is multiplied by the loop counter and the result is displayed.