+ 1

Make a program in C that make use of recursion function

Hello, I want make a program that output 1+x+x^2!+x^3/3! + ... + x^n/n! that using recursion function in C. Algorithm : 1. Declare the values of x and n 2. Display the x and n values 2. declarate variable sum = 1. Make sure sum can store numbers behind the comma 3. for i = 1 to n then 4. Look for factorial values 5. look for the power value 6. sum = number of rank and factorial from i to n 7. Display sum But, im not understand how to make the code. Please anyone help me by explaining this

8th Apr 2020, 4:20 AM
Lucky Pradana
Lucky Pradana - avatar
5 Respostas
0
^ is power ! is factorial
8th Apr 2020, 4:21 AM
Lucky Pradana
Lucky Pradana - avatar
0
@Coder Kitten I dont know, but my lecturer is give me those algorithm
8th Apr 2020, 7:20 AM
Lucky Pradana
Lucky Pradana - avatar
0
@coder kitten sum is the result of factorial and power from 1 until n (x+x^n!). i verify this with my lecturer. Also he said, he dont like pow function. he ask us to do it in classic way "(x*x)=x^2"
8th Apr 2020, 9:09 AM
Lucky Pradana
Lucky Pradana - avatar
0
what do you think about my code ? : // C program to find sum of series // 1 + x/1 + x^2/2 + x^3/3 + ....+ x^n/n #include <math.h> #include <stdio.h> //Fakctorial int factorial(int n) { int c; long r = 1; for (c = 1; c <= n; c++) r *= c; return n; } //power double sum(int x, int n) { double i, total = 3; for (i = 1; i <= n; i++) total = total + (pow(x, i) / factorial(n)); return total; } // Driver code int main() { int x = 1; int n = 1; printf("%.2f", sum(x, n)); return 0; }
8th Apr 2020, 12:16 PM
Lucky Pradana
Lucky Pradana - avatar
0
can you write the code? so i can try it by my self.
8th Apr 2020, 2:35 PM
Lucky Pradana
Lucky Pradana - avatar