Program 19) This program illustrates the use of the goto statement. The program evaluates the square root for five numbers. The variable count keeps the count of numbers read. When count is less than or equal to 5, go to read; directs the control to the label read; otherwise, the program prints a message and stops.
PROGRAM
#include <math.h>
main ( )
{
double x, y ;
int count ;
count = 1 ;
printf ("Enter FIVE real values in a LINE \N") ;
read:
scanf ("%if",&x) ;
printf("\n") ;
if (x<0)
printf ("Value - %d is negative\n" ,count) ;
else
{
y = sqrt(x) ;
printf ("%1f\t %1f\n", x, y) ;
}
count = count +1 ;
if (count <= 5)
go to read ;
printf ("\nEnd of computation") ;
getch( ) ;
}
Output: Enter FIVE real values in a LINE
50.70 40 -36 75 11.25
50.750000 7.123903
40.000000 6.324555
Value -3 is negative
75.000000 8.660254
11.250000 3.354102
End of computation
No comments:
Post a Comment