C Program to Generate Multiplication Table

by | Jan 23, 2023 | C, C Programs

Introduction

In this program, we will write a multiplication table of any value entered by the user. As we all know, writing a multiplication table is a very lengthy task, but C programming makes it very simple for users.

There are many ways in C programming to generate a multiplication table.

In this program, we will use the ‘for’ loop to complete this task.

To understand this example, you should know about

1. C programming operators

2. C for loop

Program

#include<stdio.h>
int main()
{
int num;
printf("Enter an integer\n");
scanf("%d",&num);


int i; // iterator i
for(i=1; i<=10; i++) // ‘i’ will iterate up to 10
{
printf("\n %d * %d = %d",num, i, i*num); // proper systematic statement is made so that the output looks like a multiplication table
}


return 0;
}

 

Output

Explanation

Here, the input given by the user is stored in the ‘int’ variable num.

Thereafter, we will use a ‘for’ loop to print the multiplication table up to 10.

for(i=1; i<=10; i++)

{

printf(“\n %d * %d = %d”,num, i, i*num);

}

The loop iterates from ‘i=1’ up to ‘i=10’, and in each iteration ‘num*i’ is printed.

Note :

1. Moreover, we can modify the above program by asking the user to enter the range up to which he/she wants to print the multiplication table.

2. The same program can be made using functions also. The procedure is as follows:

2.1 Declare a function by passing an ‘int’ variable as an argument and write the ‘for’ loop statement in the definition of the function.

2.2 Call the ‘main function bypassing the integer to generate the multiplication table.

 

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.