solve the questions attached in the image The TAs will not answer queries about
ID: 3544466 • Letter: S
Question
solve the questions attached in the image
The TAs will not answer queries about this question paper. Exam questions will not be explained, and no hints will be given. If you think something is unclear or ambiguous, make a reasonable assumption (one that does not contradict the question), write it at the start of your solution, and answer the question. You do not need to write header comments or inline comments for your functions. You do not need to copy any code from the question paper to your answer booklet Somewhere in the basement of the Herzberg Laboratories. Mathematics professor Dr. Polly Nomial is attempting to solve a particularly obscure mathematical theorem. She has derived the following formula. She has asked, you to write a C function named silly that has three parameters, x, y and n. Parameter x is a real number, and parameters y and n are integers. This function calculates the first n terms of the series and returns the result. Assume that you have been provided with a function that calculates factorials. The function prototype is: For values of n that are greater than or equal to 0, this function calculates and returns n! Your silly function must call factorial. Do not write factorial. The constant e is Euler's number, which is approximately 2.71828. Recall that the standard C library includes a collection of math functions, which are declared in math.h. One of these functions is: double exp(double arg); This function returns e raised to the power arg.Explanation / Answer
I think this might help:
#include<stdio.h>
#include<math.h>
int factorial(int n)
{
int i=1,fact=1;
while(i<=n)
{
fact=fact*i;
i++;
}
return (fact);
}
double calc(float x,int y,int n)
{
double val=0,e;
int i,j,f;
for(i=0,j=1;i<n,j<=n+1;i++,j=j+2)
{
f=factorial((i+1)*y+i);
e=exp(j*x);
val=val+f*e;
}
return (val);
}
int main()
{
double val;
float x;
int y,n;
printf(" Enter Value of x=:");
scanf("%f",&x);
printf(" Enter Value of y=:");
scanf("%d",&y);
printf(" Enter Value of n=:");
scanf("%d",&n);
val=calc(x,y,n);
printf(" Total Value=%lf",val);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.