Question

The language has to be in C program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. a) // function for factorial of any number. if value of n = 6, then output = 720.
let me explain you the function. value of n is passed in the function.After then we will
take an local variable i which is used in the for loop for recusively loop it untill its
value will be less than value of n. it will be done untill value of i becomes greater than
n. After then the sum of values will be stored in the output variable.
int factorial(int n)
{
int i;
int output = 1;

for (i = 1; i <= n; i++)
output = output * i;

return output;
}

b) below function will give you the sum of the series with the help of factorial method.

int factorial(int n)
{
int i;
int k;
int output = 1;
int sum = 1;
for(k=n;k<=1;k--){
for (i = 1; i <= k; i++){
output = output * i;}
   sum = sum + 1/output;}

return sum;
}

Add a comment
Know the answer?
Add Answer to:
The language has to be in C program 1. (a) rite a function, int factorial (int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program, containing the following functions. Function int recursive_fibonacci(int n) computes and returns the...

    Write a C program, containing the following functions. Function int recursive_fibonacci(int n) computes and returns the nth F(n) using recursive algorithm (i.e., recursive function call). Fibonacci numbers are defined by F(1)=F(2)=1, F(i) = F(i-1)+F(i-2), i=2,… . Function int iterative_fibonacci(int n) computes and returns the nth Fibonacci number F(n) using iterative algorithm (i.e., loop). The main function measures the memory usage and run time of iterative_fibonacci(40) and recursive_fibonacci(40), and does the comparison. To capture the execution time by millisecond, it needs...

  • In C language Write a program that includes a function search() that finds the index of...

    In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...

  • Please write in Language c using only the files stdio.h and math.h Suppose you wish to...

    Please write in Language c using only the files stdio.h and math.h Suppose you wish to find the root r of a function f(x), that is, the value r where f(r)=0. One method is to make an initial guess, x0, compute the line tangent to f at x0, and find where the tangent line intercepts the x-axis, x1. Then, use x1 as the second guess and repeat this procedure n times until f(xn) approximately equals 0 and report xn as...

  • The cosine function is analytically defined as follows: m 1. x² + x6 (-1)" x2m COS...

    The cosine function is analytically defined as follows: m 1. x² + x6 (-1)" x2m COS X = (-1)" x2n (2n)! 2!*4!- 6 + ... + (2m)! Write a complete C program that has three functions: main, cosine, and factorial. The cosine function receives a real number x and returns a real number representing the cosine of x. The cosine function also receives another integer m that determines the number of terms that will be used in computing the cosine...

  • C language Write a function to compute the power a^m, where n greaterthanorequalto 0. It should...

    C language Write a function to compute the power a^m, where n greaterthanorequalto 0. It should have the following prototype:/* Sets *p to the n' th power of a and returns 0, except * when n < 0 or p is NULL, in which case it returns -1. */int power(int a, int n, int * p); Write a unit test in a main function to test various values. The following code sequence illustrates how to use printf to provide informative...

  • PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1...

    PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1 setLocation(row : int, col : int) getRow(): int getColl): int isEmpty(): bool Details Write all the code necessary to implement the Location class as shown in the UML Class Diagram to the right. Do this in a project named snake (we'll continue adding files to this project as the term progresses). Your class definition and implementation should be in separate files. When complete, you...

  • in C language we need to find the following : EXERCISE 3: 1. Write the definition...

    in C language we need to find the following : EXERCISE 3: 1. Write the definition of a structure named employee that contains character array members for an employee's first and last names, an int member for the employee's age, a char member that contains 'M' or 'F' for the employee's gender, and a double member for the employee's hourly salary. 2. Using the above mentioned definition, write a C program that asks a user to enter the values of...

  • I must execute in C using parallel Programming techniques the following serial program: void producer_consumer(int *buffer,...

    I must execute in C using parallel Programming techniques the following serial program: void producer_consumer(int *buffer, int size, int *vec, int n) {    int i, j;    long long unsigned int sum = 0;    for(i=0;i<n;i++) {        if(i % 2 == 0) {   // PRODUCER            for(j=0;j<size;j++) {                buffer[j] = vec[i] + j*vec[i+1];            }        }        else {   // CONSUMER            for(j=0;j<size;j++) {...

  • question 3 please The first 5 questions refer to finding solutions to the equation exp(w) =...

    question 3 please The first 5 questions refer to finding solutions to the equation exp(w) = 3.8 ln(1+x). You will need to write it in the form f(x)-0, and use various root finding methods. 1. (10 pts) Plot the curves y- exp(Vx), and y 3.8 ln(1+x) on the same graph in the range 0 x 6. Read off intervals in which there are roots of the equation exp(k)- 3.8 In(1+x) Now find the roots to 6 decimal places using the...

  • Please solve the program in C++(Recursive) Write a function called factorialIterative(). This function should take a...

    Please solve the program in C++(Recursive) Write a function called factorialIterative(). This function should take a single BIG integer (bigint) as its parameter n, and it will compute the factorial n! of the value and return it as its result (as a bigint). Write this functions using a loop (do not use recursion). 2. Write the factorial function again, but using recursion. Call this function factorialRecursive(). The function takes the same parameters and returns the same result as described in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT