Fwdx_Su @ 2024-05-04 14:13:43
#include <iostream>
using namespace std ;
int main()
{
int k , n = 1 ;
// int sum = 0 ;//sum要设置成double!
double sum = 0 ;
cin >> k ;
for(int i=0 ;i<n ; i++)
{
sum = sum + 1.0/n ;//1.0的用处?
if(sum>k)
{
break ;
}
n++ ;
}
cout << n ;
}
by LiXiang190208 @ 2024-05-17 20:56:51
因为2/1是浮点型,/在小数面前为数学除(留小数),其他时候为整除
by LiXiang190208 @ 2024-05-17 20:59:51
求关注!!