[Codewars] Going to zero or to infinity?

Going to zero or to infinity?

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
class Suite
{
public:
static double going(int n) {
double res = 0, now = 1;
for(int i = n; i >= 1; now /= i, i--) res += now;
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/24/PS/Codewars/going-to-zero-or-to-infinity/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.