C program to display backward branching using goto statement.

Backward branching using goto.
Syntax-

Statement(s);
Label:
Statement(s);
.
.
goto 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();
XYZ:
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);
getch();
}

No comments:

Post a Comment