🔀⚡Beginner
Generate Multiplication Table
Generate multiplication table
This program generates the multiplication table for any number using a for loop. It demonstrates loop iteration and formatted output.
C Program to Generate Multiplication Table
multiplication_table.c
C
1#include <stdio.h>23int main() {4 int num;5 6 printf("Enter a number: ");7 scanf("%d", &num);8 9 printf("\nMultiplication Table of %d:\n", num);10 printf("============================\n");11 12 // Loop from 1 to 1013 for (int i = 1; i <= 10; i++) {14 printf("%d × %2d = %3d\n", num, i, num * i);15 }16 17 return 0;18}Output
Enter a number: 7
Multiplication Table of 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
Understanding the For Loop
for (int i = 1; i <= 10; i++)int i = 1Initialization
(runs once)
i <= 10Condition
(checked each iteration)
i++Update
(runs after each iteration)
Formatted Output Explained
| Format | Meaning | Example |
|---|---|---|
| %d | Default integer width | 7 |
| %2d | Width 2, right-aligned | 7 |
| %3d | Width 3, right-aligned | 7 |
📝 Key Takeaways
✓
for loop: init; condition; update✓
%Nd sets minimum width N✓Loop runs while condition is TRUE
✓
i++ increments i by 1Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials