#define LOOP 100
#define ACCURACY 0.0001
main()
{
int n;
float x, term, sum;
printf("Input value of x : ");
scanf("%f", &x);
sum = 0 ;
for (term = 1, n = 1 ; n < = LOOP ; ++n)
{
sum += term ;
if (term < = ACCURACY)
goto output; /* EXIT FROM THE LOOP */
term *= x ;
}
printf("\nFINAL VALUE OF N IS NOT SUFFICIENT\n");
printf("TO ACHIEVE DESIRED ACCURACY\n");
goto end;
output:
printf("\nEXIT FROM LOOP\n");
printf("Sum = %f; No.of terms = %d\n", sum, n);
end:
; /* Null Statement */
}
Output
Input value of x : .21
EXIT FROM LOOP
Sum = 1.265800; No.of terms = 7
Input value of x : .75
EXIT FROM LOOP
Sum = 3.999774; No.of terms = 34
Input value of x : .99
FINAL VALUE OF N IS NOT SUFFICIENT
TO ACHIEVE DESIRED ACCURACY