Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<math.h>
- /*
- input , n = 3
- output
- 1^2 / 1! + 2^2 / 2! + 3^2 / 3! = 4.5 ;
- */
- int main(){
- int f = 1,n,i,j;
- float sum = 0.0;
- printf("enter the number : ");
- scanf("%d",&n);
- for(j=1;j<=n;j++){
- // 1. calculate factorial of j;
- f *= j;
- // 2. add the new term to the previous term;
- sum = sum + (pow(j, 2) / (float)f);
- }
- printf("Sum = %f\n",sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement