Solve Math Equation by using a Computer Program




           In this article, we are going to solve a mathematical series with the help of a c program.


Math Equation:-

   

for -1< x <1

Now we are going to solve this problem by using c programming language. You have to paste the below code into your compiler and run this program. After that you get an Output or answer of the above equation.

Program:-

#define LOOP 100
#define ACCURACY 0.0001

int main(){
  int n;
  float x, term, sum;
  printf("Input valude 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("\n FINAL 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
return 0;
}

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
             FINAL VALUE OF N IS NOT SUFFICIENT TO ACHEVE 
             DESIRED ACCURACY 

        You can copy this code into your compiler and run this program.


Post a Comment

0 Comments