173k views
18 votes
Write the syntax of GOTO, ON GOTO and IF THEN ELSE with examples.​

User Sungguk
by
6.2k points

1 Answer

7 votes

Answer:

GOTO:

goto label;

... .. ...

... .. ...

label:

statement;

Example:

/ Program to calculate the sum and average of positive numbers

// If the user enters a negative number, the sum and average are displayed.

#include <stdio.h>

int main() {

const int maxInput = 100;

int i;

double number, average, sum = 0.0;

for (i = 1; i <= maxInput; ++i) {

printf("%d. Enter a number: ", i);

scanf("%lf", &number);

// go to jump if the user enters a negative number

if (number < 0.0) {

goto jump;

}

sum += number;

}

jump:

average = sum / (i - 1);

printf("Sum = %.2f\\", sum);

printf("Average = %.2f", average);

return 0;

}

User Asare
by
6.0k points