well i am having a bit problem in expanding sin(x).
The question says-
Q> Write a program in C to compute sin(x) =x - x^3/3! + x^5/5! -x^7/7! +....continue until the value of the next term becomes smaller than 10^-5 (in magnitude) . Test the program for x=1,x=2,x=3.In each case display the number of terms used to obtain the final answer .
I don't know what error i am doing with this code -
[/I]Please help !!Code:#include <stdio.h> #include <conio.h> #include <math.h> float denominator(int); int main() { float n, x, a, b, sum = 0; int i, j, counter = 0; printf("Enter the number x for sin(x): "); scanf("%f", &x); for (i = 1, j = 1; i <= 19, j <= 19; i++, j += 2) { a = pow(-1, i + 1) * pow(x, j); b = denominator(j); n = a / b; sum = sum + n; counter++; } printf("sin(%f)= %f \n", x, sum); printf("No. of terms used = %d", counter); getch(); } float denominator(int j) { int m; float h = 1; for (m = 1; m <= j; m++) h = h * m; return (h); }



LinkBack URL
About LinkBacks



