Created
October 9, 2017 12:17
-
-
Save snadahalli/492ca60bca8955f8c2c232a7c0276bea to your computer and use it in GitHub Desktop.
Simple C program to demonstrate goto statement
This file contains 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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment