fork(4) download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5. int n;
  6. float sum = 0,d,fact =1,j,i;
  7. printf("Enter the number:");
  8. scanf("%d",&n);
  9. for(i=1;i<=n;i++){
  10. fact = 1;
  11. for (j = 1; j <= i; j++){
  12. fact = fact * j;
  13. }
  14.  
  15. d = (float) i / (float) fact ;
  16.  
  17. sum = sum + d;
  18.  
  19. }
  20.  
  21. printf("sum = %f", sum);
  22. return 0;
  23. }
Success #stdin #stdout 0s 2164KB
stdin
5
stdout
Enter the number:sum = 2.708333