bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc037.c (869B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* The natural logarithm can be approximated by the following series.
      8     (x-1)/x + 1/2 ((x-1)/x)^2 + 1/2 ((x-1)/x)^3 + 1/2 ((x-1)/x)^4 + ...
      9 If x is input through the keyboard, write a program to calculate the
     10 sum of the first seven terms of this series. */
     11 /* Let Us C, Chap- 6, Page - 106, Qn No.: B(d) */
     12 
     13 #include <stdio.h>
     14 #include <math.h>
     15 
     16 double series(double x) // made this fn only for fun, making a fn was not necessary
     17 {
     18     double result = (x - 1) / x;
     19     int i;
     20     for (i = 2; i <= 7; i++)
     21     {
     22         result += 0.5 * pow(((x - 1) / x), i);
     23     }
     24     return result;
     25 }
     26 
     27 int main()
     28 {
     29     double x;
     30     printf("Enter the value for x : ");
     31     scanf("%lf", &x);
     32     printf("\nResult : %g", series(x));
     33     return 0;
     34 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror