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 / P036.c

P036.c (316B)


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