Printing reverse table using While Loop in C++


This is a C++ program that prompts the user to enter a limit and a number, and then prints the reverse multiplication table of that number starting from the specified limit using a while loop. Here's how the program works:

  • It declares four integer variables i, n, m, and a to store the loop counter, the limit, a placeholder, and the number for which the multiplication table is generated, respectively. The initial value of n is set to 1.
  • It prompts the user to enter the limit by printing the message "Enter the limit:" to the console using the cout object, and then reads the input from the user into the variable i using the cin object.
  • It prompts the user to enter the number for which the multiplication table is generated by printing the message "Enter the table's number:" to the console using the cout object, and then reads the input from the user into the variable a using the cin object.
  • It uses a while loop to print the reverse multiplication table of the number a starting from the limit i. The loop condition i>=n ensures that the loop continues as long as i is greater than or equal to n.
  • Inside the loop, the current value of i is printed to the console, followed by the multiplication sign *, the value of a, the equal sign =, and the product of i and a.
  • The loop counter i is then decremented by 1 using the postfix decrement operator i--.
  • The loop continues until the condition i>=n is no longer true.
  • The program then exits by returning 0 to the operating system using the return statement.

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;
    while(i>=n)
    {
        cout<<"\n"<<i<<"*"<<a<<"="<<i*a;
        i--;
    }
    return 0;
}
To download raw file Click Here

Output

Enter the limit:9
Enter the table's number:9
9*9=81
8*9=72
7*9=63
6*9=54
5*9=45
4*9=36
3*9=27
2*9=18
1*9=9

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