Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- int fact(int n)
- {
- int value = 1;
- for(int i=1;i<=n;i++)
- value *= i;
- return value;
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- double ans = 1.0;
- double temp = 1;
- for(int i=1;i<n;i++){
- temp += 2;
- double value = (double)fact(temp);
- value = 1.0/value;
- if(i%2==1){
- ans -= value;
- }
- else{
- ans += value;
- }
- }
- printf("%.4lf\n",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement