C Program to demonstrate goto statement

C Program to demonstrate goto statement . goto statement jumps the control from one point to another locally(within a function). In this program we perform a division checking for divide by zero by using the goto statement.

The Program

#include <stdio.h>
#include <stdlib.h>
main()
{
char data[100];
double num1, num2;
printf("\nPlease enter a number ==> " );
gets(data);
num1 = atof(data);
printf("\nPlease enter a number ==> " );
gets(data);
num2 = atof(data);
/* Stop a divide by zero with
* the goto statement.
*/
if ( num2 == 0.0 ) goto end_prog;
printf("\n%4.2f divided by %4.2f is %4.2f\n", num1, num2, num1/num2);
end_prog:
printf("\nProgram ended");
}
view raw goto.c hosted with ❤ by GitHub

Sample Output

Similar C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

2 comments on “C Program to demonstrate goto statement

Leave a Reply