Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main(void)
- {
- int n_terms;
- double x,y,Y,r_error=0;
- printf("Enter x: ");
- scanf("%lf",&x);
- printf("\n");
- y=log(1+x);
- printf("True value of ln(1+0.25000) = %.5f\n\n",y);
- do{
- printf("Enter a number 1-5 (0 to exit):\n");
- scanf("%d",&n_terms);
- printf("%d term(s) approximation\n",n_terms);
- switch(n_terms){
- case 5:
- Y+=pow(x,5)/5;
- case 4:
- Y-=pow(x,4)/4;
- case 3:
- Y+=pow(x,3)/3;
- case 2:
- Y-=pow(x,2)/2;
- case 1:
- Y=x;
- break;
- default:
- if(n_terms!=0){
- printf("unrecognized operator");
- continue;
- }
- printf("Approximate ln(1+0.25000) = %.5d\n",Y);
- r_error=100*(Y-y)/y;
- printf("Relative Error = %.5d%\n\n",r_error);
- }
- }while(n_terms!=0);
- }
Add Comment
Please, Sign In to add comment