C program to print multiplication table using while loop and for loop
What is a Multiplication Table?
- Its is very easy to print multiplication table using c program
- We need one for loop which iterates from 1 to 10
- Inside for loop just multiply numbers and print result in each iteration.
- Lets us see an example C program on how to print multiplication table using for loop.
- multiplication table program in c using for loop
- write a c program to input a number from user and print multiplication table of the given number using for loop. how to print multiplication table of a given number in c programming.
- #include <stdio.h>
- int main()
- {
- int n, i;
- printf("Enter a Number ");
- scanf("%d",&n);
- for(i=1; i<=10; ++i)
- {
- printf("%d * %d = %d \n", n, i, n*i);
- }
- getch();
- }
Output:
Program #2: Write a c program to print multiplication table using while loop
- #include <stdio.h>
- int main()
- {
- int n, i;
- printf("Enter a Number ");
- scanf("%d",&n);
- i=1;
- while(i<=10){
- printf("%d * %d = %d \n", n, i, n*i);
- ++i;
- }
- getch();
- }
Output:
- Enter a Number
- 2
- 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
Using a `while` Loop to Print a Multiplication Table
- #include <stdio.h>
- int main() {
- int number, i = 1;
- // Input the number for which you want to print the multiplication table
- printf("Enter a number: ");
- scanf("%d", &number);
- // Use a while loop to print the multiplication table
- printf("Multiplication Table of %d using while loop:\n", number);
- while (i <= 10) {
- printf("%d x %d = %d\n", number, i, number * i);
- i++;
- }
- return 0;
- }
- Input the Number: The program first asks the user to input a number for which the multiplication table will be generated.
- Initialize `i`: The variable `i` is initialized to 1, which will act as the multiplicand.
- While Loop Condition: As long as `i` is less than or equal to 10, the loop continues.
- Print the Result: Within the loop, the program prints the result of `number * i`.
- increment `i`: After each iteration, `i` is incremented by 1 to prepare for the next run.
Output Example:
- Enter a number: 7
- Multiplication Table of 7 using while loop:
- 7 x 1 = 7
- 7 x 2 = 14
- 7 x 3 = 21
- 7 x 4 = 28
- 7 x 5 = 35
- 7 x 6 = 42
- 7 x 7 = 49
- 7 x 8 = 56
- 7 x 9 = 63
- 7 x 10 = 70
Using a `for` Loop to Print a Multiplication Table
- #include <stdio.h>
- int main() {
- int number;
- // Input the number for which you want to print the multiplication table
- printf("Enter a number: ");
- scanf("%d", &number);
- // Use a for loop to print the multiplication table
- printf("Multiplication Table of %d using for loop:\n", number);
- for (int i = 1; i <= 10; i++) {
- printf("%d x %d = %d\n", number, i, number * i);
- }
- return 0;
- }
- Enter a number: 7
- Multiplication Table of 7 using for loop:
- 7 x 1 = 7
- 7 x 2 = 14
- 7 x 3 = 21
- 7 x 4 = 28
- 7 x 5 = 35
- 7 x 6 = 42
- 7 x 7 = 49
- 7 x 8 = 56
- 7 x 9 = 63
- 7 x 10 = 70
- Write a c program to generate fibonacci series without recursion
- Write a c program to generate fibonacci series using recursion
- Matrix multiplication in c program with explanation
- Factorial program in c without recursion
- C program to check number is armstrong number or not
- Check Armstrong number in c using recursive function
- C program for even or odd using for loop
- C program to check odd or even without using modulus operator and division operator
- Prime number program in c using for loop and while loop
- C program to print prime numbers from 1 to n
- C program to print multiplication table using while loop and for loop
- C program to convert binary to decimal using for loop
- C program to reverse a number using while loop and for loop
- C program to find sum of n numbers using for loop
- C program to find leap year using if else
- c program to check leap year using conditional operator
- C program to print patterns of numbers,alphabets and stars in a pyramid shape
- C program to swap two numbers without using third variable and using functions
- C Program to swap two numbers without using third variable
- Write a C program to swap two integer arrays
- C program for swapping of two strings
- C program to print given number in words
- C program to print 1 to 100 without using loop
- C program to find ASCII value of a string
- Convert string to integer c programming
- C program to display characters from a to z using loop
- C programming power function example program
- C program for addition subtraction multiplication and division using switch case
- C program to delete an element in an array
- C program to insert an element in an array
- Switch case in c example program
- Prime number program in c using for loop
- Fibonacci series in c without recursion