Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
C Program to Multiply two Floating Point Numbers
Next article icon

C Program to Generate Multiplication Table

Last Updated : 27 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we are creating a multiplication table in c which is a basic program for printing tables in c. We are printing multiplication tables of the number up to a given range. We will use the concepts of looping and using a 2-D array to print a Multiplication Table. 

Multiplication Table

A multiplication table is a table that shows the multiples of a number. A multiplication table is created by multiplying a constant number from 1 to a given range of numbers in repetition order. 

Input: 

num = 5  range = 10

Output:

5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50

Program to Print Multiplication Table in C

There are two approaches for printing tables in c

  1. Using loops and without storing them in an array
  2. Using loops and a 2-D array

1. Using loops and without storing them in an array 

The idea is to use the concept of looping and directly print the multiplication table without storing them in an array.

Algorithm:

  • Take the input of the number and the range of the multiplication table.
  • Declare a variable to store the product.
  • Use a for loop to directly multiply and print the Multiplication table.

C




// C program to Demonstrate the
// Multiplication table of a number
#include <stdio.h>
void print_table(int range, int num)
{
    // Declaring a variable mul to store the  product.
    int mul;
 
    // For loop to calculate the Multiplication table.
    for (int i = 1; i <= range; i++) {
        // To store the product.
        mul = num * i;
 
        // Printing the Multiplication Table.
        printf("%d * %d = %d", num, i, mul);
 
        // Proceeding to the next line.
        printf("\n");
    }
}
// Driver code
int main()
{
 
    // The range of the
    // Multiplication table
    int range = 10;
 
    // The number to calculate the
    // Multiplication table
    int num = 5;
 
    // Calling the Function.
    print_table(range, num);
 
    return 0;
}
 
 
Output
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50
  • Time Complexity: O(n), as only for loop is required.
  • Auxiliary Space: O(1), no extra space is required, so it is a constant.

2. Using loops and a 2-D array

Algorithm:

  • Take the input of the number and the range of the multiplication table.
  • Now use a for loop(variable “k”)is used to traverse the 2-D array, it iterates through 0 to the range.
  • The first column stores the number (i.e arr[k][0] = num) .
  • The second column stores the value to be multiplied (i.e arr[k][1] = k+1) .
  • The third column stores the product (i.e arr[k][2] = arr[k][1] * arr[k][0] ) .
  • Then use another loop to print the multiplication table.

C




// C program to demonstrate the
// Multiplication table of a number
#include <stdio.h>
void print_table(int range, int num)
{
    // Taking two integer variables row and column
    int row, col;
 
    // Initializing row with range of the multiplication
    // table.
    row = range;
 
    // Initializing column with 3.
    col = 3;
 
    // Creating a 2-D array to calculate and store the
    // Multiplication Table .
    int arr[row][col];
 
    // For loop to calculate the table
    for (int k = 0; k < row; k++) {
        // Storing the number in the first column.
        arr[k][0] = num;
 
        // Storing the value to be multiplied in the second
        // column.
        arr[k][1] = k + 1;
 
        // Calculating and Storing the product in the third
        // column.
        arr[k][2] = arr[k][1] * arr[k][0];
    }
 
    // For loop to print the Multiplication table
    for (int i = 0; i < row; i++) {
        printf("%d * %d = %d", arr[i][0], arr[i][1],
               arr[i][2]);
        printf("\n");
    }
}
// Driver code
int main()
{
    // The range of the
    // Multiplication table.
    int range = 10;
 
    // The number to calculate the
    // Multiplication table.
    int num = 5;
 
    // Calling the Function.
    print_table(range, num);
    return 0;
}
 
 
Output
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50

Time Complexity: O(n).

Auxiliary Space: O(row *col), as a  2-D array is used.



Next Article
C Program to Multiply two Floating Point Numbers
author
shoumikmanna
Improve
Article Tags :
  • C Language
  • C Programs
  • C Basic Programs

Similar Reads

  • C Program for Matrix Chain Multiplication | DP-8
    Write a C program for a given dimension of a sequence of matrices in an array arr[], where the dimension of the ith matrix is (arr[i-1] * arr[i]), the task is to find the most efficient way to multiply these matrices together such that the total number of element multiplications is minimum. Examples
    7 min read
  • C Program to Print Number Pattern
    A number pattern involves printing numbers in a specific arrangement or shape, often in the form of a pyramid, triangle, or other geometric shapes. They are great for practicing loops and conditional statements. In this article, we will learn how to print different number patterns in C. Rhombus Numb
    6 min read
  • C/C++ Program to Find remainder of array multiplication divided by n
    Write a C/C++ program for a given multiple numbers and a number n, the task is to print the remainder after multiplying all the numbers divided by n. Examples: Input: arr[] = {100, 10, 5, 25, 35, 14}, n = 11Output: 9Explanation: 100 x 10 x 5 x 25 x 35 x 14 = 61250000 % 11 = 9Input : arr[] = {100, 10
    3 min read
  • C Program to Multiply two Floating Point Numbers
    Floating point numbers are a way to represent real numbers with both whole parts and fractional parts. In this article, we will learn how to write a C program to find the product of two floating-point numbers. The below image shows an example of floating point multiplication in C: C Program To Multi
    1 min read
  • Matrix Multiplication in C
    A matrix is a collection of numbers organized in rows and columns, represented by a two-dimensional array in C. Matrices can either be square or rectangular. In this article, we will learn the multiplication of two matrices in the C programming language. ExampleInput: mat1[][] = {{1, 2}, {3, 4}} mat
    3 min read
  • C Program To Print Character Pyramid Pattern
    Pyramid patterns is a classic logical programming exercise where a triangular looking pattern is printed by treating the output screen as a matrix and printing a given character. In this article, we will explore how to print various alphabet pyramid patterns using C program. Half Pyramid PatternHalf
    4 min read
  • C Program to Print Pyramid Pattern
    In C, a pyramid pattern consists of numbers, stars, or alphabets arranged in a triangular shape. In this article, we will learn how to print different shapes of pyramid patterns using C program. Following are the 6 common pyramid patterns: Right Half Pyramid PatternRight half pyramid pattern looks l
    13 min read
  • Pascal Triangle Program in C
    Pascal’s Triangle is a triangular array of numbers where each number is the sum of the two numbers directly above it. The triangle starts with 1 at the top, and each subsequent row contains the coefficients of binomial expansions. In this article, we will learn how to print Pascal's Triangle in C. P
    2 min read
  • C Program For Printing Inverted Pyramid
    An Inverted Pyramids are inverted triangular patterns where the base is at the top, and the rows decrease in size as they move downwards. In this article, we will learn how to print different types of inverted pyramid patterns using C program. There can be 3 types of inverted pyramid patterns: Inver
    7 min read
  • C Program to Make a Simple Calculator
    A simple calculator is a program that can perform addition, subtraction, multiplication, and division of two numbers provided as input. In this article, we will learn to create a simple calculator program in C. Example Input: a = 10, b = 5, op = +Output: 15.00Explanation: Chosen operation is additio
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences