Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C program to Generate multiplication table

C program to Generate multiplication table

Posted on October 19, 2020October 19, 2020

Table of Contents

  • C program to Generate multiplication table
    • program to Generate multiplication table
      • Code to Generate multiplication table using for loop
      • Code to Generate multiplication table using while loop
      • Code to Generate multiplication table using do-while loop
      • Code to Generate multiplication table using function
      • Code to Generate multiplication table using recursion

C program to Generate multiplication table

In this article, we will discuss the concept of C program to Generate multiplication table.

In this program, we are going to learn how to generate a multiplication table in C programming language.

This is done using for loop , while loop , do-while loop , function and recursion

program to Generate multiplication table

Code to Generate multiplication table using for loop

In this program, we will  display multiplication table of given number using for loop in C language.

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num,i;
    printf("Enter an integer\n");
    scanf("%d",&num);
    for(i=1; i<=10; i++){
        printf("%d * %d = %d\n",num,i,num*i);
    }
    getch();
    return 0;
}

When the above code is executed,it produces the following result

Enter an  integer

12

12 * 1 = 12
12 * 2 = 24
12 * 3 = 36
12 * 4 = 48
12 * 5 = 60
12 * 6 = 72
12 *  7 = 84
12 * 8 = 96
12 *  9 = 108
12 * 10 = 120

 

  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanf() function and store to the variable num
  • Create a for loop of i from 1 to 10 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table using printf() function.

 

Code to Generate multiplication table using while loop

In this program, we will  display multiplication table of given number using while loop in C language.

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num,i;
    printf("Enter an integer\n");
    scanf("%d",&num);
    i=1;
    while(i<=10){
        printf("%d * %d = %d\n",num,i,num*i);
         i++;
    }
    getch();
    return 0;
}

When the above code is executed,it produces the following result

Enter an  integer

15

15 * 1 = 15
15 * 2 = 30
15 * 3 = 45
15 * 4 = 60
15 * 5 = 75
15 * 6 = 90
15 *  7 = 105
15 * 8 = 120
15 *  9 = 135
15 * 10 = 150


  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanf() function and store to the variable num
  • Create a while loop of i from 1 to 10 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table using printf() function.

 

Code to Generate multiplication table using do-while loop

In this program, we will  display multiplication table of given number using do-while loop in C language.

Program 3

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num,i;
    printf("Enter an integer\n");
    scanf("%d",&num);
    i=1;
    do{
        printf("%d * %d = %d\n",num,i,num*i);
         i++;
    }while(i<=10);
    getch();
    return 0;
}

When the above code is executed,it produces the following result

Enter an  integer

8

8 * 1 = 8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 *  7 = 56
8 * 8 = 64
8 *  9 = 72
8 * 10 = 80

 

  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using scanf() function and store to the variable num
  • Create a do-while loop of i from 1 to 10 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table using printf() function.

 

Code to Generate multiplication table using function

In this program, we will  display multiplication table of given number using function in C language.

Program 4

#include <stdio.h>
#include <stdlib.h>
void mulTable(int);
int main()
{
    int num;
    printf("Enter a positive number\n");
    scanf("%d",&num);
    printf("\nMutiplication table for %d is\n",num);
    mulTable(num);
    getch();
    return 0;
}
void mulTable(int num)
{
    int count;
    for(count=1; count<=12; count++ ){
         printf("%d x %d = %d\n",num,count,num*count);
    }
}

When the above code is executed,it produces the following result

 

  • Declare a function named as mulTable(int); with integer parameter
  • integer variables num is declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using scanf() function and store the variable num.
  • Define the function  mulTable(int); to print mutiplication table
  • Call the function to produce output
  • finally, the program displays the multiplication table using printf) function.

 

Code to Generate multiplication table using recursion

In this program, we will  display multiplication table of given number using recursion in C language

Program 5

#include <stdio.h>
#include <stdlib.h>
void mulTable(int,int);
int main()
{
    int num,i=1;
    printf("Enter a positive number\n");
    scanf("%d",&num);
    printf("\nMutiplication table for %d is\n",num);
    mulTable(num,i);
    getch();
    return 0;
}
void mulTable(int num,int i)
{
    if(i>10){
        return 0;
    }
    else
    {
        printf("%d*%d=%d\n",num,i,num*i);
        return mulTable(num,i+1);
    }
}

When the above code is executed,it produces the following result

C program to Generate multiplication table
Generate multiplication table

Suggested post

for loop in C language

while loop in C language

Do-while loop in C language

if statements in C language

Operator in C language

 

Similar post

Program to Display multiplication table in Java

Program to Display multiplication table in C

Program to Display multiplication table in C++

Program to Display multiplication table in Python

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes