PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on Loops

Program to print multiplication table of any number

Input - Output

Input
Enter number to print table: 3

Output
3 * 1 = 3

3 * 2 = 6

3 * 3 = 9

3 * 4 = 12

3 * 5 = 15

.........

.........

3 * 10 = 30

Algorithm

Step 1: START

Step 2: Enter number to print table

Step 3: Start a loop from I = 1 to 10.

Step 4: Print the result R = n*I.

Step 5: End the loop

Step 6: END

CODE


/* Print multiplication table of any number */

#include<stdio.h>
int main()
{
      int num;
      printf(" Enter the number : ");
      scanf("%d",&num);
      printf(" Multiplication table of %d : \n",num);
      for(int i=1;i<=10;i++)
      printf("%d * %d = %d\n",num,i,num*i);
    return 0;
}


/* Print multiplication table of any number */

#include<iostream>
using namespace std;
int main()
{
      int num;
      cout<<" Enter the number : ";
      cin>>num;
      cout<<" Multiplication table of %d : "<<num<<endl;
      for(int i=1;i<=10;i++)
      cout<<num <<" * "<<i<<" = "<<num*i<<endl;
    return 0;
}

OutPut

Enter number to print table: 3

3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30