-1
#include<iostream>
using namespace std;
int main(){
    double s=0;
    double p=1;
    int n;
       cin>>n;
 for(int i=1 ; i<=n ; i++){
    for(int j=1 ; j<=i; j++){
       p=p*(1/i);
  }
    s=s+p;
    p=1;
}
  cout<<s;
  return 0;
}

I should count the sum of: (1/1)^1 + (1/2)^2 +...+(1/n)^n . But maybe my logic is wrong because the program returns number 1.

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

1

You are doing integral division, the numerator as double

Use :

 p = p* ( 1.0/i );
P0W
  • 46,614
  • 9
  • 72
  • 119