求助,c++ 递归函数 读入的数随机分成2,3,4等份,计算可以分成多少小于0.1部分,急急急!l

2025-03-14 12:56:03
推荐回答(1个)
回答1:

#include 
#include 
#include 
using namespace std;

int partition(double weight) {
        if (weight <= 0.1)
                return 1;
        int parts = rand() % 3 + 2;
        cout<<"weight:"<        return parts*partition(weight / parts);
}

int main()
{
        srand(time(NULL));
        cout<        cout<        cout<        return 0;
}

暂且这么写,这样每次划分好像结果都不一样的说。