Author Topic: Turbo C Program for series: 1/2+2/3+3/4+4/5.........n/n+1  (Read 2847 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Turbo C Program for series: 1/2+2/3+3/4+4/5.........n/n+1
« on: March 16, 2012, 04:04:24 am »
Here is the Turbo C Program for series:  1/2+2/3+3/4+4/5.........n/n+1

Code:
//Source Code Listing

#include <stdio.h>

void main()
{
   int i, n;
   float sum = 0, term = 0;
   printf("Program for series:  1/2+2/3+3/4+4/5.........n/n+1");
   printf("\nEnter number: ");
   scanf("%d", &n);
   
   for(i = 1; i <= n; i++)
   {
      term = (float) i / (i+1);
      sum = sum + term;
      printf("\nTerm: %-5d Value = %.4f Sum = %.4f", i, term, sum);
   }
   printf("\n\n");
}


output

Program for series:  1/2+2/3+3/4+4/5.........n/n+1
Enter number: 10

Term: 1     Value = 0.5000 Sum = 0.5000
Term: 2     Value = 0.6667 Sum = 1.1667
Term: 3     Value = 0.7500 Sum = 1.9167
Term: 4     Value = 0.8000 Sum = 2.7167
Term: 5     Value = 0.8333 Sum = 3.5500
Term: 6     Value = 0.8571 Sum = 4.4071
Term: 7     Value = 0.8750 Sum = 5.2821
Term: 8     Value = 0.8889 Sum = 6.1710
Term: 9     Value = 0.9000 Sum = 7.0710
Term: 10    Value = 0.9091 Sum = 7.9801

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