bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_1 / tuition-c / P037.c

P037.c (375B)


      1 /* sum = 1 + 1+2/1*2 + 1+2+3/1*2*3 + ... + 1+2+3+...+n/1*2*3*...*n */
      2 
      3 #include <stdio.h>
      4 
      5 int main()
      6 {
      7     double sum = 0, temp1 = 0, temp2 = 1;
      8     int n, i;
      9     printf("Enter value for n : ");
     10     scanf("%d", &n);
     11     for (i = 1; i <= n; i++)
     12     {
     13         temp1 += i;
     14         temp2 *= i;
     15         sum += temp1 / temp2;
     16     }
     17     printf("\nSum = %g", sum);
     18     return 0;
     19 }