Niloy007

Shahin's Problem

Jul 21st, 2020
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include<math.h>
  3. /*
  4. input , n = 3
  5. output
  6. 1^2 / 1! + 2^2 / 2! + 3^2 / 3! = 4.5 ;
  7.  
  8. */
  9. int main(){
  10.     int f = 1,n,i,j;
  11.     float sum = 0.0;
  12.     printf("enter the number : ");
  13.     scanf("%d",&n);
  14.  
  15.     for(j=1;j<=n;j++){
  16.     // 1. calculate factorial of j;
  17.     f *= j;
  18.     // 2. add the new term to the previous term;
  19.         sum = sum + (pow(j, 2) / (float)f);
  20.     }
  21.     printf("Sum = %f\n",sum);
  22.  
  23.     return 0;
  24. }
RAW Paste Data