Printing tables using For Loop in C++


This is a C++ program that prints the multiplication table of a given number up to a certain limit. Here's how the program works:

  • It declares four integer variables i, n, m, and a.
  • It prompts the user to enter the limit and the table number.
  • It reads in the values of n and a from the user.
  • It uses a for loop to iterate from i = 1 to i = n.
  • Inside the for loop, it prints the multiplication of i and a.
  • Finally, it returns 0 to indicate successful completion of the program.

Source Code

#include<iostream>
using namespace std;
int main()
{
    int i,n,m,a;
    cout<<"\nEnter the limit:";
    cin>>n;
    cout<<"\nEnter the table number:";
    cin>>a;
    for(i=1;i<=n;i++)
    {
        cout<<"\n"<<i<<"*"<<a<<"="<<i*a;
    }
    return 0;
}
To download raw file Click Here

Output

Enter the limit:10
Enter the table number:5
1*5=5
2*5=10
3*5=15
4*5=20
5*5=25
6*5=30
7*5=35
8*5=40
9*5=45
10*5=50

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples