Thursday, February 12, 2015

C program to find sum of series 1 1 2 2 1 3 3 1 n n


C++ program to find sum of series 1+1/2^2+1/3^3+.....+1/n^n

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main()
{
clrscr();
double sum=0,a;
int n,i;
cout<<"1+1/2^2+1/3^3+.....+1/n^n";
cout<<"
Enter value of n:";

cin>>n;

for(i=1;i<=n;++i)
{
a=1/pow(i,i);
sum+=a;
}

cout<<"Sum="<<sum;
getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.