Write a C code to make a table of ( x , x - x 3 /6 + x 5 /120, sin x ) using fun
ID: 3549771 • Letter: W
Question
Write a C code to make a table of (x , x - x3/6 + x5/120, sin x) using functions in the format of
x
x - x3/6 + x5/120
sin (x)
0.0
2.000
1.000
0.1
1.901
1.105
0.2
1.808
1.221
...
...
...
2.0
8.000
7.389
Note: The values above are not correct.
This is what I have so far:
#include <stdio.h>
float f(float x)
{
return x*x ;
}
/* main */
int main()
{
int i;
printf(" x f(x) ");
printf("----------------- ");
for (i=0; i< 10; i++) printf( " (fill in your code) ", 0.1*i, f(0.1*i));
return 0;
x
x - x3/6 + x5/120
sin (x)
0.0
2.000
1.000
0.1
1.901
1.105
0.2
1.808
1.221
...
...
...
2.0
8.000
7.389
Explanation / Answer
#include<stdio.h>
#include<math.h>
int main()
{
double x;
for(x=0;x<=2;x+=.1)
{
printf("%lf %lf %lf",x,x-pow(x,3)/6+pow(x,5)/120, sin(x-pow(x,3)/6+pow(x,5)/120));
printf(" ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.