Write a C Program to Multiplication table

C Program to Multiplication table

Introduction:

This C program generates a multiplication table for a given number up to a specified range. It takes user input for the number and the range, and then displays the multiplication table in the console.

Explanation:

  1. We start by including the necessary header file #include <stdio.h> for input and output operations.
  2. The multiplicationTable function takes two parameters – number and upTo. It prints the multiplication table for the given number up to the specified range.
  3. In the main function, we prompt the user to enter the number for which they want the multiplication table and the range up to which the table should be generated.
  4. User inputs are stored in baseNumber and tableRange variables.
  5. The multiplicationTable function is then called with the user-provided inputs.
  6. The program concludes by returning 0, indicating successful execution.

Program:

#include <stdio.h>
int main()
{
int a, i;
printf("Enter a number: ");
scanf("%d",&a);
for(i=0; i<=5; ++i)
{
printf("%d * %d = %d \n", a, i, a*i); 
}
return 0;
}
}

Output:

Enter a number: 7
7 * 0 = 0
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35 

Conclusion:

This C program demonstrates a simple way to generate a multiplication table based on user input. It incorporates functions to enhance modularity and readability. The program takes advantage of basic input/output operations and a loop to efficiently generate and display the multiplication table. Users can easily understand and modify this program for different requirements.

Scroll to Top