POJ - 1003

簡單題 c++練手ios

#include<iostream>
using namespace std;
int tiaohe(double n);
int main(){
    double num = 0;
    cin >> num;
    while (num != 0)
    {
        cout << tiaohe(num) << " card(s)" << endl;
        cin >> num;
    }
    return 0;
}
int tiaohe(double n){
    double sum = 0;
    int i = 1;
    do{
        i++;
        sum += 1.0 / i;
    } while (sum <= n);

    return i - 1;
}
相關文章
相關標籤/搜索