假如拿出本金4万买股票,一个月买入一次卖出一次算交易1次,每一手股票交易一次赚100元每个月交易一次,每手股票2000元第一个月能买20手。将赚到的钱全部用来买股票且从来不亏损,那么3年之内能赚多少?
下面写了个程序来计算这个问题。当然是越到后面赚的钱越多,
# include<stdio.h>static int total_sum = 0;
static int sum_yu = 0;
static int inc_roundlot = 20;// 只取余是不对的,假如41手,那么41*100=4100。取余只能得到100,
// 实际上可以增加2手股票再余100元。因此这里要处理此问题。
void recursion(int d_sum){if(d_sum - 2000 >= 2000){inc_roundlot++;recursion(d_sum - 2000);}
}/*** sum_yu * inc_roundlot 股票交易手数* */
void count_sum(int month){int roundlot = 0, d_sum = 0;roundlot = inc_roundlot + month;d_sum = roundlot * 100; // 每个月每一手交易一次赚100元printf("roundlot = %d, d_sum = %d\n", roundlot, d_sum);recursion(d_sum);sum_yu += d_sum % 2000;if(sum_yu >= 2000){sum_yu -= 2000; inc_roundlot++;}total_sum = roundlot * 2000;printf("total_sum = %d, ", total_sum);total_sum += sum_yu;printf("total_sum = %d\n\n", total_sum);
}int main(void)
{int i = 0;for(; i < 76; i++){printf("month: %d, ", i);count_sum(i);month++;}return 0;
}
运行结果:
month: 0, roundlot = 20, d_sum = 2000
total_sum = 40000, total_sum = 40000month: 1, roundlot = 21, d_sum = 2100
total_sum = 42000, total_sum = 42100month: 2, roundlot = 22, d_sum = 2200
total_sum = 44000, total_sum = 44300month: 3, roundlot = 23, d_sum = 2300
total_sum = 46000, total_sum = 46600month: 4, roundlot = 24, d_sum = 2400
total_sum = 48000, total_sum = 49000month: 5, roundlot = 25, d_sum = 2500
total_sum = 50000, total_sum = 51500month: 6, roundlot = 26, d_sum = 2600
total_sum = 52000, total_sum = 52100month: 7, roundlot = 28, d_sum = 2800
total_sum = 56000, total_sum = 56900month: 8, roundlot = 29, d_sum = 2900
total_sum = 58000, total_sum = 59800month: 9, roundlot = 30, d_sum = 3000
total_sum = 60000, total_sum = 60800month: 10, roundlot = 32, d_sum = 3200
total_sum = 64000, total_sum = 64000month: 11, roundlot = 34, d_sum = 3400
total_sum = 68000, total_sum = 69400month: 12, roundlot = 35, d_sum = 3500
total_sum = 70000, total_sum = 70900month: 13, roundlot = 37, d_sum = 3700
total_sum = 74000, total_sum = 74600month: 14, roundlot = 39, d_sum = 3900
total_sum = 78000, total_sum = 78500month: 15, roundlot = 41, d_sum = 4100
total_sum = 82000, total_sum = 82600month: 16, roundlot = 43, d_sum = 4300
total_sum = 86000, total_sum = 86900month: 17, roundlot = 45, d_sum = 4500
total_sum = 90000, total_sum = 91400month: 18, roundlot = 47, d_sum = 4700
total_sum = 94000, total_sum = 94100month: 19, roundlot = 50, d_sum = 5000
total_sum = 100000, total_sum = 101100month: 20, roundlot = 52, d_sum = 5200
total_sum = 104000, total_sum = 104300month: 21, roundlot = 55, d_sum = 5500
total_sum = 110000, total_sum = 111800month: 22, roundlot = 57, d_sum = 5700
total_sum = 114000, total_sum = 115500month: 23, roundlot = 60, d_sum = 6000
total_sum = 120000, total_sum = 121500month: 24, roundlot = 63, d_sum = 6300
total_sum = 126000, total_sum = 127800month: 25, roundlot = 66, d_sum = 6600
total_sum = 132000, total_sum = 132400month: 26, roundlot = 70, d_sum = 7000
total_sum = 140000, total_sum = 141400month: 27, roundlot = 73, d_sum = 7300
total_sum = 146000, total_sum = 146700month: 28, roundlot = 77, d_sum = 7700
total_sum = 154000, total_sum = 154400month: 29, roundlot = 81, d_sum = 8100
total_sum = 162000, total_sum = 162500month: 30, roundlot = 85, d_sum = 8500
total_sum = 170000, total_sum = 171000month: 31, roundlot = 89, d_sum = 8900
total_sum = 178000, total_sum = 179900month: 32, roundlot = 93, d_sum = 9300
total_sum = 186000, total_sum = 187200month: 33, roundlot = 98, d_sum = 9800
total_sum = 196000, total_sum = 197000month: 34, roundlot = 103, d_sum = 10300
total_sum = 206000, total_sum = 207300month: 35, roundlot = 108, d_sum = 10800
total_sum = 216000, total_sum = 216100month: 36, roundlot = 114, d_sum = 11400
total_sum = 228000, total_sum = 229500