C Online Compiler
Example: Multiplication Table using While Loop in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Multiplication Table using While Loop #include <stdio.h> int main() { // Step 1: Declare variables for the user's number and the loop counter. int num; int i = 1; // Initialize the counter before the loop // Step 2: Prompt the user to enter a number. printf("Enter an integer: "); // Step 3: Read the integer input from the user. scanf("%d", &num); // Step 4: Print a header for the multiplication table. printf("\nMultiplication Table of %d:\n", num); // Step 5: Use a while loop to iterate from 1 to 10. while (i <= 10) { // Step 6: Inside the loop, calculate and print each line. printf("%d x %d = %d\n", num, i, num * i); // Step 7: Increment the counter manually to avoid an infinite loop. i++; } return 0; }
Output
Clear
ADVERTISEMENTS