fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3. int enter()
  4. {
  5. int n;
  6. do{
  7. printf("Enter n: ");
  8. scanf("%d",&n);
  9. }while(n<1);
  10. return n;
  11. }
  12. float sum_f(int n)
  13. {
  14. int i,gt=1;
  15. float f=0;
  16. for(i=1; i<=n; i++)
  17. {
  18. gt=gt*i;
  19. f=f+1.0/gt;
  20. }
  21. return f;
  22. }
  23. main()
  24. {
  25. int n;
  26. float f;
  27. n=enter();
  28. f=sum_f(n);
  29. printf("Sum of part A is %f",f);
  30. }
  31.  
Success #stdin #stdout 0s 9424KB
stdin
4
stdout
Enter n: Sum of part A is 1.708333