Printing Multiplication Table Using For Loop in C Programming


This program is written in the C programming language and is used to generate and print the multiplication table of a given number up to a given limit. The program starts by including the standard input/output library (stdio.h) and then defines a main function. Within the main function, the program declares three variables: "i", "n" and "a". The variable "n" is used to store the limit entered by the user, "a" is used to store the number for which the multiplication table is to be generated and "i" is used as a loop counter.

The program then prompts the user to enter the limit using the "printf" function and stores the value in the variable "n" using the "scanf" function. Next, it prompts the user to enter the number for which the multiplication table is to be generated, and stores the value in the variable "a" using the "scanf" function. Next, the program uses a "for" loop with the counter variable "i" to iterate from 1 to the value of "n". Within this loop, it uses the "printf" function to print the current value of "i", the value of "a" and the result of multiplying "i" and "a" on each iteration of the loop.

Finally, the program returns 0 to indicate that the program has completed successfully. This program will take two inputs from the user, one is the limit to which the table should be generated and another is the number for which the table should be generated. The program then uses a for loop to iterate from 1 to the limit, and in each iteration, it multiplies the number entered by the user and the current value of the counter and prints the result.

Source Code

#include<stdio.h>
int main()
{
  int i,n,m,a;
  printf("\nEnter the limit:");
  scanf("%d",&n);
  printf("\nEnter the table number:");
  scanf("%d",&a);
  for(i=1;i<=n;i++)
  {
    printf("\n%d*%d=%d",i,a,i*a);
  }
  return 0;
}
To download raw file Click Here

Output

Enter the limit:8
Enter the table number:2
1*2=2
2*2=4
3*2=6
4*2=8
5*2=10
6*2=12
7*2=14
8*2=16

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C