Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

EXAMPLE OF exit WITH goto STATEMENT in a FOR loop

Posted By: Blaze Fischer     Category: C Programming     Views: 2714

EXAMPLE OF exit WITH goto STATEMENT in a FOR loop

Code for EXAMPLE OF exit WITH goto STATEMENT in a FOR loop in C Programming

#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
  
Share: 


Didn't find what you were looking for? Find more on EXAMPLE OF exit WITH goto STATEMENT in a FOR loop Or get search suggestion and latest updates.

Blaze Fischer
Blaze Fischer author of EXAMPLE OF exit WITH goto STATEMENT in a FOR loop is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!