-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeriesSum.c
More file actions
35 lines (28 loc) · 715 Bytes
/
Copy pathSeriesSum.c
File metadata and controls
35 lines (28 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <math.h>
// Function to calculate factorial of a number
long long factorial(int num) {
long long fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
return fact;
}
// Function to calculate the sum of the series
double sum_of_series(int x, int n) {
double sum = 0.0;
for (int i = 1; i <= n; i++) {
sum += (double) (pow(x, i)) / factorial(i);
}
return sum;
}
int main() {
int x, n;
printf("Enter the value of x: ");
scanf("%d", &x);
printf("Enter the number of terms (n): ");
scanf("%d", &n);
double result = sum_of_series(x, n);
printf("The sum of the series is: %.2f\n", result);
return 0;
}