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

kathir

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

Code:
//Source Code Listing

#include <stdio.h>
#include <math.h>

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

   printf("\n\n");
}

output:

Program for series: 1+(1/2)^2+(1/3)^3+(1/4)^4+...
Enter number: 5

Term: 1     Value = 1.0000 Sum = 1.000000
Term: 2     Value = 0.2500 Sum = 1.250000
Term: 3     Value = 0.0370 Sum = 1.287037
Term: 4     Value = 0.0039 Sum = 1.290943
Term: 5     Value = 0.0003 Sum = 1.291263

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