Advertisement
Imran1107048

Asif 2(c)

Nov 4th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. int fact(int n)
  5. {
  6. int value = 1;
  7. for(int i=1;i<=n;i++)
  8. value *= i;
  9. return value;
  10. }
  11. int main()
  12. {
  13. int n;
  14. scanf("%d",&n);
  15. double ans = 1.0;
  16. double temp = 1;
  17. for(int i=1;i<n;i++){
  18. temp += 2;
  19. double value = (double)fact(temp);
  20. value = 1.0/value;
  21. if(i%2==1){
  22. ans -= value;
  23. }
  24. else{
  25. ans += value;
  26. }
  27. }
  28. printf("%.4lf\n",ans);
  29. return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement