fork download
  1. #include <stdio.h>
  2. int fact(int n)
  3. {
  4. int i,fact=1;
  5. for(i=1;i<=n;i++)
  6. {
  7. fact=fact*i;
  8. }
  9. return fact;
  10. }
  11.  
  12. int SumOfFirstNterms(int n)
  13. {
  14. int sum=0,i;
  15. for(i=1;i<=n;i++)
  16. {
  17. sum=sum+fact(i)/i;
  18. }
  19. return sum;
  20. }
  21. int main(void) {
  22. int n,res;
  23. printf("Enter n: ");
  24. scanf("%d",&n);
  25. res = SumOfFirstNterms(n);
  26. printf("Sum Of First N terms is %d",res);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 5288KB
stdin
5
stdout
Enter n: Sum Of First N terms is 34