Skip to content

Instantly share code, notes, and snippets.

@snadahalli
Created October 9, 2017 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snadahalli/492ca60bca8955f8c2c232a7c0276bea to your computer and use it in GitHub Desktop.
Save snadahalli/492ca60bca8955f8c2c232a7c0276bea to your computer and use it in GitHub Desktop.
Simple C program to demonstrate goto statement
#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