Monday, June 18, 2012

To show the implementation of goto statement


/* Program to show the implementation of goto statement */

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

  double x,y;

  int count=1;

  clrscr();

  read:

    printf("\nEnter real number:\n");

    scanf("%lf",&x);

    printf("\n");

    if(x<0)

      printf("Value %d position is negative\n",count);

    else

    {

      y=sqrt(x);

      printf("\nSquare root of %lf is %lf\n",x,y);

    }

    count=count+1;

  if(count<=5)

    goto read;

  printf("\nEnd of compilation!");

  getch();

}

 

OUTPUT

Enter real number:

25.48

 

Square root of 25.480000 is 5.047772

 

Enter real number:

-40.23

 

Value 2 position is negative

 

Enter real number:

52.98

 

 

Square root of 52.980000 is 7.278736

 

Enter real number:

75.96

 

 

Square root of 75.960000 is 8.715503

 

Enter real number:

-77.77

 

Value 5 position is negative

 

End of compilation!

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.