#include <iostream> #include <stdio.h> /* printf, scanf, puts, NULL */ #include <stdlib.h> /* srand, rand */ #include <time.h> /* time */ using namespace std; int main(void) { int total = 10; int num = 8; int minuim = 0.01; srand (time(NULL)); for(int i = 1; i< num; i++){ float safe = (total - (num - i) * minuim)*1.0/(num - i); float money = (rand() %(int) (safe*100 - minuim* 100 ) + minuim * 100) * 1.0 / 100; cout << i <<" " << " money = "<< money << " res = "<< total - money <<endl; total -= money; } cout << 8 << " " << " money = "<< total << " res = "<< 0 <<endl; }