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
  • DSA
  • Practice Mathematical Algorithm
  • Mathematical Algorithms
  • Pythagorean Triplet
  • Fibonacci Number
  • Euclidean Algorithm
  • LCM of Array
  • GCD of Array
  • Binomial Coefficient
  • Catalan Numbers
  • Sieve of Eratosthenes
  • Euler Totient Function
  • Modular Exponentiation
  • Modular Multiplicative Inverse
  • Stein's Algorithm
  • Juggler Sequence
  • Chinese Remainder Theorem
  • Quiz on Fibonacci Numbers
Open In App
Next Article:
Recursive Program to print multiplication table of a number
Next article icon

Program to print multiplication table of a number

Last Updated : 13 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
Try it on GfG Practice
redirect icon

Given a number n, we need to print its table. 

Examples : 

Input: 5
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

Input: 2
Output:
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

Iterative Approach

The iterative approach for printing a multiplication table involves using a loop to calculate and print the product of a given number and the numbers in range from 1 to 10. In this method, you begin with the number whose table you want to print and use a loop to multiply it with increasing values.

C++
// CPP program to print table of a number #include <iostream> using namespace std;  void printTable(int n) {    for (int i = 1; i <= 10; ++i)          cout << n << " * " << i << " = "                << n * i << endl; }  int main() {     int n = 5;       printTable(n);     return 0; } 
C
#include <stdio.h>  void printTable(int n) {      for (int i = 1; i <= 10; ++i)          printf("%d * %d = %d\n", n, i, n * i); }  int main() {     int n = 5;       printTable(n);     return 0; } 
Java
// Java program to print table of a number  import java.io.*;  class GfG {      public static void printTable(int n)  {                        for (int i = 1; i <= 10; ++i)              System.out.println(n + " * " + i +                                " = " + n * i);     }        public static void main(String arg[]){            int n = 5;  		printTable(n);     } } 
Python
# Python Program to print table of a number  def printTable(n):      for i in range (1, 11):                   # multiples from 1 to 10         print ("%d * %d = %d" % (n, i, n * i))   if __name__ == "__main__":   n = 5   printTable(n) 
C#
// C# program to print table of a number  using System;  class GfG {     public static void printTable(int n) {                  for (int i = 1; i <= 10; ++i)              Console.Write(n + " * " + i +                               " = " + n *                                 i + "\n");     }        public static void Main()   {        int n = 5;        printTable(n);      } } 
JavaScript
// Javascript program to print // table of a number  function printTable(n) {  for (let i = 1; i <= 10; ++i)     console.log( n + " * " +i +             " = " + n *                 i); }  // Driver Code let n = 5;  printTable(n); 

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(1)
Space Complexity – O(1)

Illustration

Step by step execution of loop for the multiplication table of n = 5.

We have n = 5, and the loop will iterate from i = 1 to i = 10.

First Iteration (i = 1):

  • The loop multiplies n = 5 by i = 1.
  • Result: 5 * 1 = 5.
  • Output: 5 * 1 = 5.

Second Iteration (i = 2):

  • The loop multiplies n = 5 by i = 2.
  • Result: 5 * 2 = 10.
  • Output: 5 * 2 = 10.

Third Iteration (i = 3):

  • The loop multiplies n = 5 by i = 3.
  • Result: 5 * 3 = 15.
  • Output: 5 * 3 = 15.

….
….

Tenth Iteration (i = 10):

  • The loop multiplies n = 5 by i = 10.
  • Result: 5 * 10 = 50.
  • Output: 5 * 10 = 50.

Recursive Approach

In this method, we pass i as an additional parameter with initial value as 1. We print n * i and then recursively call for i+1. We stop the recursion when i becomes 11 as we need to print only 10 multiples of given number and i.

C++
#include <iostream> using namespace std;  // printTable() prints table of number and takes // 1 required value that is number of whose teble // to be printed and an optional input i whose d // efault value is 1 void printTable(int n, int i = 1) {     if (i == 11)         return;     cout << n << " * " << i << " = " << n * i << endl;     i++;     printTable(n, i); }  int main() {     int n = 5;     printTable(n); } 
C
#include <stdio.h>  // printTable() prints table of number and takes // 1 required value that is number of whose table // to be printed and an optional input i whose default value is 1 void printTable(int n, int i) {     if (i == 11)         return;     printf("%d * %d = %d\n", n, i, n * i);     i++;     printTable(n, i); }  int main() {     int n = 5;     printTable(n, 1);     return 0; } 
Java
import java.util.*;   class GfG {       // printTable() prints table of number and takes     // 1 required value that is number of whose teble to be     // printed and an optional input i whose default value is 1     static void printTable(int n, Integer... val)  {           int i = 1;         if (val.length != 0)             i = val[0];         if (i == 11) // base case             return;         System.out.println(n + " * " + i + " = " + n * i);         i++;          printTable(n, i);     }       public static void main(String[] args) {         int n = 5;         printTable(n);     } }   
Python
# printTable() prints table of number and takes # 1 required value that is number of whose teble to be printed # and an optional input i whose default value is 1 def printTable(n, i=1):      if (i == 11):  # base case         return     print(n, "*", i, "=", n * i)     i += 1       printTable(n, i)  if __name__ == "__main__":   n = 5   printTable(n) 
C#
using System; using System.Collections.Generic;  class GfG {    // print_table() prints table of number and takes   // 1 required value that is number of whose teble to be   // printed and an optional input i whose default value is 1   static void printTable(int n, int i = 1) {     if (i == 11) // base case       return;     Console.WriteLine(n + " * " + i + " = " + n * i);     i++;     printTable(n, i);   }      public static void Main(string[] args) {     int n = 5;     printTable(n);   } } 
JavaScript
// printTable() prints table of number and takes //1 required value that is number of whose teble to be printed //and an optional input i whose default value is 1  function printTable(n, i = 1) {     if (i == 11)// base case         return;     console.log(n + " * " + i + " = " + n * i);     i++;     printTable(n,i); }  // Driver Code let n = 5; printTable(n); 

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(1)
Space Complexity – O(1)



Next Article
Recursive Program to print multiplication table of a number
https://media.geeksforgeeks.org/auth/avatar.png
GeeksforGeeks
Improve
Article Tags :
  • DSA
  • Mathematical
  • Basic Coding Problems
Practice Tags :
  • Mathematical

Similar Reads

  • Recursive Program to print multiplication table of a number
    Given a number N, the task is to print its multiplication table using recursion. Examples Input: N = 5 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 Input: N = 8 Output: 8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 *
    5 min read
  • Multiplication of two numbers with shift operator
    For any given two numbers n and m, you have to find n*m without using any multiplication operator. Examples : Input: n = 25 , m = 13 Output: 325 Input: n = 50 , m = 16 Output: 800 Method 1We can solve this problem with the shift operator. The idea is based on the fact that every number can be repres
    7 min read
  • Program to print factors of a number in pairs
    Given a number n, the task of the programmer is to print the factors of the number in such a way that they occur in pairs. A pair signifies that the product of the pair should result in the number itself. Examples: Input : 24Output : 1*24 2*12 3*8 4*6Input : 50Output : 1*50 2*25 5*10The simplest app
    6 min read
  • Program to print ASCII Value of all digits of a given number
    Given an integer N, the task is to print the ASCII value of all digits of N. Examples: Input: N = 8Output: 8 (56)Explanation:ASCII value of 8 is 56 Input: N = 240Output:2 (50)4 (52)0 (48) Approach: Using the ASCII table shown below, the ASCII value of all the digits of N can be printed: DigitASCII V
    5 min read
  • Program to calculate product of digits of a number
    Given a number, the task is to find the product of the digits of a number. Examples: Input: n = 4513 Output: 60 Input: n = 5249 Output: 360 General Algorithm for product of digits in a given number: Get the numberDeclare a variable to store the product and set it to 1Repeat the next two steps till t
    7 min read
  • Program to print numbers in digital form
    Given a number n then print the number in Digital form. Examples : Input : 5 Output : - - | - - | - - Input : 8 Output : - - | | - - | | - - Explanation: Take a matrix of size 5*5 and store 0 and 1 in the matrix. If matrix cell is 0 then it is used for space and if matrix cell is 1 then it is used e
    15+ min read
  • Kth Smallest Number in Multiplication Table
    Given three integers m, n, and k. Consider a grid of m * n, where mat[i][j] = i*j (1 based indexing). The task is to return the k'th smallest element in the m*n multiplication table. Examples: Input: m = 3, n = 3, k = 5Output: 3Explanation: The 5th smallest element is 3. Input: m = 2, n = 3, k = 6Ou
    13 min read
  • Efficient program to print the number of factors of n numbers
    Given an array of integers. We are required to write a program to print the number of factors of every element of the given array.Examples: Input: 10 12 14 Output: 4 6 4 Explanation: There are 4 factors of 10 (1, 2, 5, 10) and 6 of 12 and 4 of 14. Input: 100 1000 10000 Output: 9 16 25 Explanation: T
    15 min read
  • Program to print numbers columns wise
    We have to print natural numbers columns wise with decreasing size, depending upon given number of lines as described in the examples below. Examples : Input : 5 Output : 1 2 6 3 7 10 4 8 11 13 5 9 12 14 15 Input : 3 Output : 1 2 4 3 5 6 Approach : We will take the outer for loop, which is for how m
    4 min read
  • Multiply a number with 10 without using multiplication operator
    Given a number, the task is to multiply it with 10 without using multiplication operator?Examples: Input : n = 50 Output: 500 // multiplication of 50 with 10 is = 500 Input : n = 16 Output: 160 // multiplication of 16 with 10 is = 160 A simple solution for this problem is to run a loop and add n wit
    5 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