求Sum[pow((1/i),2){i,1,n}]:
#include <iostream>
using namespace std;
int main()
{
double i,n,sum=0;
cout<<"input n="<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
sum=sum+(1/i)*(1/i);
}
cout<<"sum="<<sum<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
double i,n,sum=0;
cout<<"input n="<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
sum=sum+(1/i)*(1/i);
}
cout<<"sum="<<sum<<endl;
return 0;
}