Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i want to write a C program function of the following equation : i have tried re

ID: 3624604 • Letter: I

Question

i want to write a C program function of the following equation :

i have tried recursion but my program crashes everytime , can anyone help ?

the function should be like this :

double F(double x) ,  test the fuction for x = 2 , should give -0.444444

 

here is my code :

# include <stdio.h>
# include <math.h>
# include <stdlib.h>
 
double factorial(double n)
{
    if(n==0) return 1;
    else
    return n*factorial(n-1);
}
double F(double x)
{
    double k = 2;
    return Si(pow(-1,k)*(pow(x,(2*k)+1)))/(((2*k)+1)*(factorial((2*k)+1)));
}


int main()
{
    int i;
    double x = 2;
   
    printf("F(f%) = %f ",x,F(x));
    system("pause");
    return 0;
}

Explanation / Answer

please rate - thanks

it can't be -0.444444 because your starting with 2.

the 2nd term is -0.444444

I ran it setting k2-the number of terms to 20

# include <stdio.h>
# include <math.h>
# include <stdlib.h>

double factorial(double n)
{
    if(n==0) return 1;
    else
    return n*factorial(n-1);
}
double F(double x)
{   double tot=0;
    int k2 = 20;
    int k;
    for(k=0;k<k2;k++)
         tot=tot+(pow(-1,k)*pow(x,(2*k+1)))/((2*k+1)*factorial(2*k+1));
    return tot;
   
}


int main()
{
    int i;
    double x = 2;
  
    printf("F(%f) = %f ",x,F(x));
    system("pause");
    return 0;
}