Skip to content

Commit

Permalink
3
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafatKarim committed Aug 4, 2023
1 parent af6ddec commit a9dbcd0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions solutions/sharafat/10/3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <math.h>

int factorial(int n)
{
if (n == 1)
return 1;
else
return n * factorial(n - 1);
}

float evaluate(int x, int n, int i)
{
if (n >= 10)
return 0;
else if (i % 2 == 0)
return -pow(x, n) / factorial(n) + evaluate(x, n + 2, i+1);
else
return pow(x, n) / factorial(n) + evaluate(x, n + 2, i+1);
}

int main()
{
int n;
scanf("%d", &n);
printf("%f\n", evaluate(n, 1, 1));
}

0 comments on commit a9dbcd0

Please sign in to comment.