The mathematical constant \"e\" can be expressed as an infinite series: e = 1 +
ID: 2081421 • Letter: T
Question
The mathematical constant "e" can be expressed as an infinite series: e = 1 + 1/1! + 1/2! + 1/3! + ... Write a program that will print an approximate value of "e" by computing the series out to 1/n!, where n is an integer entered by the user. In other words, calculate: e = 1 + 1/1! + 1/2! + ... + 1/n! The Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13,... where each number (after the first two values) is the sum of the previous two numbers. Write a program that declares an integer array called fib_numbers with a length of 25 elements. The program then fills the array with the first 25 Fibonacci numbers using a loop. The program then prints the values to the screen using a separate loop. Write a function that determines the average of the values in an array. In the main() function declare a floating point array with a length of 8 elements, and have the user enter the value of each element using a loop. The program should then call and pass the array to the function, then display the average.Explanation / Answer
2). Code :
#include <stdio.h>
double sumfunction(double);
main()
{
double num,sum;
printf(" Enter the value: ");
scanf("%lf", &num);
sum = sumfunction(num);
printf(" Sum of the above series = %lf ", sum);
}
double sumfunction(double n)
{
double result = 1, k= 1, i;
for (i = 1; i <= n; i++)
{
k = k * i;
result = result +(1 / k);
}
return(result);
}
output:
Enter the value: 4
Sum of the above series = 2.708333
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.