Multiplication Table in C
  • Twitter
  • Facebook
  • Snapchat
  • Instagram

C Program to Print Multiplication Table Using While and Do-While Loops

šŸ“‘ On this page:
  • Introduction
  • Multiplication Table Using While Loop
  • Multiplication Table Using Do-While Loop
  • Practice Exercises
  • Frequently Asked Questions
šŸ“š In this tutorial, you will learn:
  • How to print a multiplication table using while loop in C
  • How to print a multiplication table using do-while loop in C
  • The difference between while and do-while loops
  • How to take user input and display the table
  • Practice exercises to strengthen your understanding

Introduction

In this tutorial, we'll learn how to print the multiplication table of a number using while and do-while loops in C. Knowing how to control loops is an important skill for programmers, especially when you need to generate sequences or process data repeatedly.

The main idea is simple: with a loop, you start from a number and keep multiplying and increasing it until you reach your limit. The while loop checks the condition first, and if it's true, it runs the code inside. The do-while loop, on the other hand, runs the code at least once before checking the condition.

1. Multiplication Table Using While Loop

How to print a multiplication table with a while loop

In the first program, we ask the user to enter a number and set a variable j to 1. Then, as long as j is less than or equal to 10, the program prints the multiplication line and increases j by 1. This process continues until j becomes 11, and at that point, the loop stops. As a result, the program prints the multiplication table from 1 to 10.

C Program Code to Print Multiplication Table Using While Loop

#include <stdio.h>

int main() {
    int j = 1, n;

    printf("Enter Any Number\n");
    scanf("%d", &n);

    printf("\n Table of %d is:", n);
    while(j <= 10)
    {
        printf(" %d ", n * j);
        j++;
    }

    printf("\n");
    return 0;
}
                                    

Output

Enter Any Number
5

 Table of 5 is:
 5  10  15  20  25  30  35  40  45  50 
                                

How This Program Works

When you run this program, it allocates memory for two integer variables: j, which starts at 1 to track our steps, and n, which holds the input number. The computer displays "Enter Any Number" on the screen and pauses at the scanf function until you type a value. If you enter 5, that value is saved directly into n, and the program prints the heading line "Table of 5 is:" to format the output.

Next, the execution path reaches the while loop and tests the condition j <= 10. Since j is currently 1, the test passes, and the program moves inside the loop block. It multiplies n * j (5 x 1), prints the result 5 on the screen, and encounters the j++ statement, which increases our counter to 2 before jumping straight back up to the loop check.

This cycle repeats smoothly as j climbs. On the next passes, the program verifies the condition, prints the calculated products like 10, 15, and 20, and increments the counter by 1 each time. The loop spins continuously until j prints 50 and reaches 11. At that moment, the condition becomes false, the loop stops, and the program prints a final new line to finish up cleanly.


2. Multiplication Table Using Do-While Loop

How to print a multiplication table with a do-while loop

The second program asks the user to enter a number. It then uses a do-while loop to print the multiplication table starting from 1 up to 10. The loop runs at least once, printing the calculated result and then increasing j. It keeps doing this until j is greater than 10. So, if you enter 5, it will print the multiplication table for 5 from 1 to 10.

C Program Code to Print Multiplication Table Using Do-While Loop

#include <stdio.h>

int main() {
    int j = 1, n;

    printf("\nEnter any Number.");
    scanf("%d", &n);

    printf("Table of %d:\n", n);

    do {
        printf("%d ", n * j);
        j++;
    } while(j <= 10);

    printf("\n");
    return 0;
}
                                    

Output

Enter any Number.
5
Table of 5:
5 10 15 20 25 30 35 40 45 50 
                                

How This Program Works

When you run the program, it initializes the loop counter j to 1 and prompts you to enter a number. If you enter 5, that value is stored in the variable n, and the program prints the heading text "Table of 5:".

Next, the execution path enters the do block directly without checking any conditions upfront. It immediately multiplies n * j (5 x 1), prints the result 5 to the screen, and increments j to 2 using the j++ statement.

Only after completing this pass does the program check the condition while(j <= 10) at the bottom. Since 2 is less than 10, it jumps back to the top of the loop. This cycle repeats, printing the remaining products until j reaches 11, where the condition fails and the loop stops cleanly.

Practice Exercises

šŸ“ Exercise 1: Reverse Multiplication Table

Print the multiplication table in reverse order (from 10 down to 1).

Show Solution
#include <stdio.h>

int main() {
    int j = 10, n;
    printf("Enter Any Number\n");
    scanf("%d", &n);
    printf("Table of %d (Reverse):\n", n);
    while(j >= 1) {
        printf("%d ", n * j);
        j--;
    }
    return 0;
}
                                        

šŸ“ Exercise 2: Custom Range Table

Print a multiplication table up to a user-defined limit N (like 5 x 15 or 5 x 20).

Show Solution
#include <stdio.h>

int main() {
    int j = 1, n, limit;
    printf("Enter Number: ");
    scanf("%d", &n);
    printf("Enter Limit: ");
    scanf("%d", &limit);
    printf("Table of %d up to %d:\n", n, limit);
    while(j <= limit) {
        printf("%d ", n * j);
        j++;
    }
    return 0;
}
                                        

Frequently Asked Questions

How does a C program print a multiplication table using a while loop?

To print a multiplication table using a while loop in C, the program takes a number input from the user and initializes a counter variable j to 1. The while loop runs as long as j is less than or equal to 10. Inside the loop, the program multiplies the input number by j, prints the formatted result, and increments j by 1 during each iteration.

How do you generate a math table using a do-while loop in C?

Using a do-while loop, the program first executes the multiplication and printing statements inside the loop body for the initial value of the counter j (which starts at 1). After printing the row and incrementing j, the loop condition 'j <= 10' is evaluated at the bottom. The loop continues to execute until j exceeds 10.

Why do we initialize the loop counter variable 'j' to 1 for tables?

Standard multiplication tables traditionally start by multiplying the target number by 1 and end at 10. Initializing the counter variable j to 1 ensures the table starts from the very first multiple rather than zero or a random garbage value.

Can we print a multiplication table beyond 10 using these C loops?

Yes, you can easily change the termination limit. By replacing the hardcoded condition 'j <= 10' with a user-defined variable 'N' (like j <= N), the program can dynamically print the multiplication table up to any range the user desires.

šŸ’” Tip: Always ensure your loop has a valid termination condition to avoid infinite loops.

šŸ“– Related Tutorials

  • While Loop in C
  • Do-While Loop in C
  • For Loop in C
  • Difference Between While and Do-While

Previous Topic: -->> Difference Between While and Do-While   ||   Next topic: -->> Even Numbers in C


šŸ”„ C While & Do-While Loop Programs (Practice Set 1)

šŸš€ Practice the most important C while loop and do-while loop programs asked in exams and interviews. These beginner-to-advanced problems will help you master loop concepts quickly.

  1. C Program to Print Odd Numbers from 1 to N (While & Do-While)

    Learn how to print odd numbers using loops in C. A basic problem to understand loop iteration.

  2. C Program to Print Even Numbers from 1 to N

    Understand how to display even numbers using while and do-while loops in C.

  3. C Program to Print Uppercase Alphabets (A to Z)

    Print all uppercase letters using loops. Helps in understanding ASCII values and iteration.

  4. C Program to Print Lowercase Alphabets (a to z)

    Simple loop program to print lowercase alphabets in C.

  5. C Program to Print Numbers from 1 to 10

    Basic beginner example to understand number printing using loops.

  6. C Program to Print Multiplication Table using While Loop

    Take user input and generate a multiplication table. Common interview question.

  7. C Program to Check Positive, Negative or Zero

    Check number type continuously using loops until user exits.

  8. C Program to Find Factorial using While Loop

    Calculate factorial using loops. Important for coding interviews.

  9. C Program to Find Sum of First N Natural Numbers

    Compute sum from 1 to N using loop logic. Core beginner problem.

  10. C Program to Print Prime Numbers from 1 to N

    Learn prime number logic using nested loops in C programming.

  11. C Program to Print Armstrong Numbers from 1 to N

    Understand Armstrong number logic using loops and mathematical operations.

  12. C Program to Print Leap Years using While Loop

    Find leap years using conditions and loops. Useful for real-world logic building.

  13. C Program to Reverse a Number using While Loop

    Reverse digits of a number using loops. Frequently asked interview question.

šŸ“˜ Practice/Assignment Set 2: C While & Do-While Loop Series Programs

1. C Program to Find Sum of Squares from 1 to N using While Loop
Learn how to calculate the sum of squares (1² + 2² + 3² + ... + N²) using while and do-while loops in C. This is a commonly asked logic-building problem in exams and coding interviews.

2. C Program to Find Sum of First N Natural Numbers using While Loop
Write a C program to calculate the sum of natural numbers (1 + 2 + 3 + ... + N) using loops. A basic and important program for beginners learning loop concepts.

3. C Program to Find Sum of Series (1/1! + 2/2! + ... + N/N!)
Practice a slightly advanced loop problem by computing the sum of factorial-based series using while or do-while loops. Helps strengthen logic and mathematical programming skills.

4. C Program to Find Sum of Harmonic Series (1 + 1/2 + 1/3 + ... + 1/N)
Learn how to calculate the harmonic series using loops in C. This program improves understanding of floating-point calculations and loop control.

5. C Program to Find Sum of Series (1 + 3²/3³ + 5²/5³ + ... up to N Terms)
Solve an advanced series-based problem using while loop logic. This type of question is frequently asked in competitive programming and technical interviews.

Other Tutorials
SQL FAQ  Java FAQ  Python FAQ

šŸ“š Explore More Topics

šŸ—„ļø SQL Interview Questions & Answers

SQL SELECT Statement FAQ SQL Restricting & Sorting Data FAQ SQL Group Functions & Aggregated Data FAQ SQL Multiple Tables (JOINs) FAQ SQL Subqueries FAQ SQL DML Statements (Managing Tables) FAQ SQL Indexes, Synonyms & Sequences FAQ SQL DDL (Tables & Relationships) FAQ SQL Views FAQ SQL Indexing Best Practices FAQ SQL Window & Analytic Functions FAQ

šŸ Python Interview Questions & Answers

Python Interview Questions Python Syntax & Variables FAQ Python Data Types FAQ Python If-Else FAQ Python Loops FAQ Python Functions Interview Q Python String Manipulation FAQ Python Lists & Dictionaries FAQ Python Tuples & Sets FAQ Python Exception Handling FAQ Python OOP Interview Questions

ā˜• Java Interview Questions & Answers

Java Introduction Interview Q Java Development Environment FAQ Java Data Types FAQ Java Control Flow & Operators FAQ Java Basic Input/Output FAQ Java Arrays FAQ Java Strings FAQ Java Methods FAQ Java Basic OOP Concepts FAQ Java Advanced OOP Concepts FAQ Java OOP Best Practices FAQ Java Exception Handling FAQ Java Synchronization FAQ Java Threads & Concurrency FAQ Java Collection Framework FAQ Java File I/O & Serialization FAQ Java Serialization & Deserialization FAQ Java Features FAQ Java Inner & Anonymous Classes FAQ Java Memory Management FAQ Java Packages FAQ Java Wrapper Classes FAQ Java Streams & Lambda FAQ

C Language

  • Home
  • Why C Language
  • History of C Language
  • Applications of C Language
  • Introduction To C
    • What is Program?
    • Structure of C Program
    • Working Of C Program
    • CHARACTER SET
    • VARIABLES AND IDENTIFIERS
    • BUILT-IN DATA TYPES
    • OPERATORS AND EXPRESSIONS
    • CONSTANTS AND LITERALS
    • SIMPLE ASSIGNMENT STATEMENT
    • BASIC INPUT/OUTPUT STATEMENT
    • SIMPLE 'C' PROGRAMS
    • Assignments
  • Operators in C Programming
    • Arithmetic Operators
    • Assignment Operators
    • Increment and Decrement Operators
    • Relational Operators
    • Logical Operators
    • Bitwise Operators
    • Other Operators
    • Assignments
  • Conditional Statements
    • DECISION MAKING WITHIN A PROGRAM
    • CONDITIONS
    • IF STATEMENT
    • IF-ELSE STATEMENT
    • IF-ELSE LADDER
    • NESTED IF-ELSE
    • SWITCH CASE
    • Assignments
  • Loops Statements
    • Introduction to Loops
    • GO TO Statement
    • Do while Loop
    • While Loop
    • Nested While Loop
    • Difference Between While and Do while
    • Difference Between Goto and loop
    • while loop assignments
    • C FOR Loop
    • C For loop examples
    • Nested for loop
    • Nested for loop examples
    • Infinite while Loops
    • Infinite for Loops
    • Continue in Loops
    • break in Loops
    • difference while do..while & for
    • Assignments
  • Arrays
    • One Dimensional Array
    • Declaring 1D Arrays
    • Initilization of 1D arrays
    • Accessing element of one 1D Array
    • Read and Display 1D Arrays
    • Two Dimensional Arrays
    • Declare 2D Arrays
    • Read and Display 2D Arrays
    • Assignments/Examples
  • Functions
    • Introduction
    • Need For User-Defined Function
    • Multiple Function Program
    • Modular Programming
    • Elements Of User Defined Function
    • Function Definition
    • Function Declaration
    • Types of functions
    • Nesting of Function
    • Recursion
    • Passing Array To Functions
    • Scope,Visibility and Lifetime of Variables
    • Assignments
  • Structure
    • Introduction
    • Array vs Structure
    • Defining Structure
    • Declaring Structure Variables
    • Type Defined Structure
    • Accessing Structure Members
    • Structure Initilization
    • Copying & Comparing Structure Variables
    • Array of Structure
    • Arrays Within Structure
    • Structures Within Structures
    • Structures and Functions
    • Structure Examples/Assignments
  • Union
    • Define Union
    • Create and use Union
    • Difference Between Structure and Union
    • Union Examples
    • Union FAQ
  • Pointers
    • What Are Pointers In C?
    • How Do We Use Pointers In C?
    • Declaration Of A Pointer
    • The Initialization Of A Pointer
    • Syntax Of Pointer Initialization
    • Use Of Pointers In C
    • The Pointer To An Array
    • The Pointer To A Function
    • The Pointer To A Structure
    • Types Of Pointers
    • The Null Pointer
    • The Void Pointer
    • The Wild Pointer
    • The Near Pointer
    • The Huge Pointer
    • The far Pointer
    • dangling pointer
    • Accessing Pointers- Indirectly And Directly
    • Pros Of Using Pointers In C
    • Cons Of Pointers In C
    • Applications Of Pointers In C
    • The & Address Of Operator In C
    • How To Read The Complex Pointers In C?
    • Practice Problems On Pointers
  • File Processing
    • File Handling In C
    • Types Of Files In C
    • Operations Done In File Handling
    • File Examples
    • Binary Files
    • count words,lines in a file
    • Copy files
    • Update File
    • count vowels in a file
  • Preprocessor
    • Macro substitution division
    • File Inclusion
    • Conditional Compilation
    • Other directives
    • Examples
  • Dynamic Memory Allocation
    • malloc
    • calloc
    • free
    • realloc
    • Examples
  • Storage Classes
  • Graphics
  • Frequently Asked Interview Questions (FAQ)
    • Introduction To C FAQ
    • Operators FAQ
    • Conditional Statements FAQ
    • Loops FAQ
    • Arrays FAQ
    • Function FAQ
    • Structure FAQ
    • Pointers FAQ
    • Files FAQ
    • Storage classes FAQ
    • Dynamic Memory FAQ
  • Programs/Assignments
    • Introduction To C
    • Operators
    • Conditional Statements
    • Loops
    • Arrays
    • Function
    • Structure
    • Pointers
    • Files
    • Storage classes
    • Dynamic Memory
  • Case Studies
  • Multiple Choice Questions
    • Introduction To C MCQ
    • Operators MCQ
    • Conditional Statements MCQ
    • Loops MCQ
    • Arrays MCQ
    • Function MCQ
    • Structure MCQ
    • Pointers MCQ
    • Files MCQ
    • Storage classes MCQ
    • Dynamic Memory MCQ
    • More MCQ

Get in touch

  • tech2dsm@gmail.com

© Sankalan Data Tech. All rights reserved.