Forward branching using goto.
Syntax-
Statement(s);
goto Label;
Statement(s);
.
.
Label:
Example-
C program to calculate squareroot of given number.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(){
int n;
float s;
clrscr();
printf("Enter a positive integer\n");
scanf("%d",&n);
if (n<=0) goto XYZ;
s=sqrt(n);
printf("sqrt of %d = %f\n",n,s);
XYZ:
getch();
}
No comments:
Post a Comment