Ques:-20) Write a program to print the multiplication table of the number entered by the user.

Below is a C program that prints the multiplication table for a number entered by the user:

				
					#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int tab,num;
printf("enter the number\n");
scanf("%d",&num);
printf("-------%d table------\n",num);
for(int i=1;i<=10;i++)
{
tab=num*i;
printf("%d*%d=%d\n",num,i,tab);
}
getch();
return 0;
}

				
			

Out Put

				
					Enter a number to print its multiplication table: 5
Multiplication table for 5:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

				
			

Another Exampe

				
					#include <stdio.h>

int main() {
    int number, i;

    printf("Enter a number to print its multiplication table: ");
    scanf("%d", &number);

    printf("Multiplication table for %d:\n", number);

    for (i = 1; i <= 10; i++) {
        printf("%d x %d = %d\n", number, i, number * i);
    }

    return 0;
}

				
			

Explanation:

  1. User Input:

    • The program uses scanf to read an integer input from the user, which specifies the number for which the multiplication table will be printed.
  2. Printing the Multiplication Table:

    • A for loop iterates from 1 to 10.
    • In each iteration, it calculates the product of the input number and the loop index (i) and prints the result in the format number x i = product.
				
					Enter a number to print its multiplication table: 5
Multiplication table for 5:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

				
			

Compile and run this C program. The program will prompt the user to enter a number, and then it will print the multiplication table for that number from 1 to 10.

Scroll to Top