![if !IE]> <![endif]>
The goto statement is a control statement which is used to transfer the control from one place to another place without any condition in a program.
The syntax of the goto statement is;
In the syntax above, label is an identifier. When goto label; is encountered, the control of program jumps to label: and executes the code below it.
using namespace std;
float num, average, sum = 0.0;
int i, n;
cout<< "Maximum number of inputs: ";
for(i = 1; i<= n; ++i)
cout<< "Enter n" <<i<< ": ";
// Control of the program move to jump: goto jump;
sum += num;
average = sum / (i - 1);
cout<< "\nAverage = " << average; return 0;
Maximum number of inputs: 5
Enter n1: 10
Enter n2: 20
Enter n3: -2 Average = 15
In the above program the average of numbers entered by the user is calculated. If the user enters a negative number, it is ignored the average of numbers entered. Until that point is calculated.
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.