Priniting Reverse tables using Goto Statement in C++


This program prints the multiplication table of a given number in reverse order from the given limit down to 1 using a goto statement. Here's how it works:

  • The program prompts the user to enter the limit and the number whose multiplication table is to be printed.
  • The label start marks the beginning of a loop that calculates and prints the multiplication table.
  • In each iteration of the loop, the program prints the product of the current number (n) and the given number (a).
  • The variable n is decremented by 1 in each iteration.
  • The loop continues until n becomes less than or equal to 0.
  • At this point, the program exits the loop and terminates.

Although this program works correctly, it uses a goto statement, which is generally considered to be bad programming practice. Using goto can make the code harder to read and understand, and can lead to subtle bugs and errors. A better approach would be to use a for or while loop to iterate over the values of n, without using goto. This would make the program more readable and easier to maintain.

Source Code

#include<iostream>
using namespace std;
int main()
{
    int n,a;
    cout<<"\nEnter the limit :";
    cin>>n;
    cout<<"\nEnter the table's number:";
    cin>>a;
    start:
        cout<<"\n"<<n<<"*"<<a<<"="<<n*a;
        n--;
        if(n>0)
        {
            goto start;
        }
    return 0;
}
To download raw file Click Here

Output

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

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