The while loop can be used to generate the multiplication table of a number. In this program, the user enters a number, and the loop starts from 1 and continues up to 10. During each iteration, the entered number is multiplied by the current value of the loop variable and the result is displayed in table format.
How It Works?
k with 1.while loop checks whether k <= 10.k and display the result.k by 1.#include <stdio.h> #include <conio.h> main() { int k, no; clrscr(); printf("\nEnter any number : "); scanf("%d", &no); k = 1; while(k <= 10) { printf("\n%d * %d = %d", no, k, no * k); k = k + 1; } getch(); }
while loop to display the multiplication table of a number entered by the user from 1 to 20.while loop to perform repeated multiplication and display a complete multiplication table.k with 1. Use the while loop condition k <= 20. Multiply the entered number with k and increase the value of k by 1 after every iteration.#include <stdio.h> #include <conio.h> main() { int k, no; clrscr(); printf("\nEnter any number : "); scanf("%d", &no); k = 1; while(k <= 20) { printf("\n%d * %d = %d", no, k, no * k); k = k + 1; } getch(); }
k with 1. The while loop runs until k becomes greater than 20. In each iteration, the program multiplies the entered number with k and displays the result. After printing each table value, k is increased by 1.