Program 21 - CSU1128 - CSE 2026 - Shoolini University

Program to print the table of the number entered by the user. Example 2 = 2 x 1 = 2

Explanation

The program prints the multiplication table of a number entered by the user.

Header

The code begins with including the standard input-output header file using #include <stdio.h>.

Variable Declaration

The main() function is defined, and two integer variables d and m are declared.

Program Description

The program prints a description message for the user to understand its functionality.

User Input

The user is prompted to enter a number for which they want to print the multiplication table. The input is read using scanf("%d", &d);.

Table Printing

The program prints the multiplication table for the entered number using a for loop:

  • for (m = 1; m <= 10; m++): Loops from 1 to 10.
  • printf("\t %d x %d = %d \n", d, m, d * m);: Prints the current multiplication result in the format d x m = result.

Program End

The program ends with printf("\n"); to print a new line and return 0; to indicate successful execution.

Code

                    
/*
 * -----------------------------------------------------------
 * Logic Building with Computer Programming (CSU1128)
 * Instructor: Dr. Pankaj Vaidya | Author: Divya Mohan
 * 
 * This code is a part of the educational initiative by dmj.one
 * with aim of empowering and inspiring learners in the field of
 * Computer Science and Engineering through the respective courses.
 * 
 * (c) 2022, Divya Mohan for dmj.one. All rights reserved.
 * -----------------------------------------------------------
 */

#include <stdio.h>
int main()
{
    int d, m;
    printf("\n\n Program to print the table of the number entered by the user. Example 2 = 2 x 1 = 2 \n\n");

    printf("Enter a number for which you want to print its table (Example: 21) - and press enter: ");
    scanf("%d", &d);
    printf("\nTable for the entered number %d is:\n", d);

    for (m = 1; m <= 10; m++)
    {
        printf("\t %d x %d = %d \n", d, m, d * m);
    }

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

Output

Program to print the table of the number entered by the user. Example 2 = 2 x 1 = 2

Enter a number for which you want to print its table (Example: 21) - and press enter: 4

Table for the entered number 4 is:
 4 x 1 = 4
 4 x 2 = 8
 4 x 3 = 12
 4 x 4 = 16
 4 x 5 = 20
 4 x 6 = 24
 4 x 7 = 28
 4 x 8 = 32
 4 x 9 = 36
 4 x 10 = 40