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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} |
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”
atof(data) means
atof is a function to convert a string to floating point number.