Guest User

Untitled

a guest
Jul 23rd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main(void)
  4. {
  5. int n_terms;
  6. double x,y,Y,r_error=0;
  7. printf("Enter x: ");
  8. scanf("%lf",&x);
  9. printf("\n");
  10. y=log(1+x);
  11. printf("True value of ln(1+0.25000) = %.5f\n\n",y);
  12. do{
  13. printf("Enter a number 1-5 (0 to exit):\n");
  14. scanf("%d",&n_terms);
  15. printf("%d term(s) approximation\n",n_terms);
  16. switch(n_terms){
  17. case 5:
  18. Y+=pow(x,5)/5;
  19. case 4:
  20. Y-=pow(x,4)/4;
  21. case 3:
  22. Y+=pow(x,3)/3;
  23. case 2:
  24. Y-=pow(x,2)/2;
  25. case 1:
  26. Y=x;
  27. break;
  28. default:
  29. if(n_terms!=0){
  30. printf("unrecognized operator");
  31. continue;
  32. }
  33. printf("Approximate ln(1+0.25000) = %.5d\n",Y);
  34. r_error=100*(Y-y)/y;
  35. printf("Relative Error = %.5d%\n\n",r_error);
  36. }
  37. }while(n_terms!=0);
  38. }
Add Comment
Please, Sign In to add comment