Author Topic: Turbo C Program for series 1 + 1 / x + 1 / x^2 + 1 / x^3 + 1 / x^4 + ...  (Read 1055 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Here is Turbo C Program for X series and N terms value for the series: Y = 1 + 1 / x + 1 / x^2 + 1 / x^3 + 1 / x^4 + ...

Code:
//Source Code Listing

#include <stdio.h>
#include <conio.h>

void main()
{
   int i;
   float x, xterm;
   int numterms = 5;
   float sum = 1;
   printf("Enter number X: ");
   scanf("%f", &x);
   xterm = x;
   for(i = 1; i <= numterms; i++)
   {
      sum = sum + 1.0 / xterm;
      xterm = xterm * x;
      printf("\nTerm: %d Sum = %.4f", i, sum);
   }
   printf("\n\n");
   return;
}

Output:
Enter number X: 5

Term: 1 Sum = 1.2000
Term: 2 Sum = 1.2400
Term: 3 Sum = 1.2480
Term: 4 Sum = 1.2496
Term: 5 Sum = 1.2499

Press any key to continue . . .

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1