Printing reverse tables using For Loop in C++
This is a C++ program that prompts the user to input a limit and a number, and then outputs the multiplication table of that number up to the limit in reverse order. Here is a brief explanation of the program:
- The program declares four integer variables: i, n, m, and a, and initializes n to 1 and i to the limit entered by the user.
- The program prompts the user to input the limit and the number, and reads them from the standard input using the cin object.
- The program enters a for loop that iterates i-n+1 times, where n is 1 and i is the limit entered by the user. In each iteration, the loop body is executed.
- In the loop body, the program outputs the current value of i and the product of i and a, separated by the * and = characters, respectively. The output is sent to the standard output using the cout object.
- After the loop terminates, the program returns 0 to the operating system, indicating successful execution.
Source Code
#include<iostream>
using namespace std;
int main()
{
int i,n=1,m,a;
cout<<"\nEnter the limit:";
cin>>i;
cout<<"\nEnter the table's number:";
cin>>a;
for(i;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's number:5
10*5=50
9*5=45
8*5=40
7*5=35
6*5=30
5*5=25
4*5=20
3*5=15
2*5=10
1*5=5