首页 > 其他分享 >突发奇想股票增长指数

突发奇想股票增长指数

时间:2024-07-27 21:50:39浏览次数:6  
标签:突发奇想 指数 int 股票 sum month 2000 roundlot total

假如拿出本金4万买股票,一个月买入一次卖出一次算交易1次,每一手股票交易一次赚100元每个月交易一次,每手股票2000元第一个月能买20手。将赚到的钱全部用来买股票且从来不亏损,那么3年之内能赚多少?

下面写了个程序来计算这个问题。当然是越到后面赚的钱越多,第36个月可以买108手。这就是复利的威力!

# 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 = 40000

month: 1, roundlot = 21, d_sum = 2100
total_sum = 42000,  total_sum = 42100

month: 2, roundlot = 22, d_sum = 2200
total_sum = 44000,  total_sum = 44300

month: 3, roundlot = 23, d_sum = 2300
total_sum = 46000,  total_sum = 46600

month: 4, roundlot = 24, d_sum = 2400
total_sum = 48000,  total_sum = 49000

month: 5, roundlot = 25, d_sum = 2500
total_sum = 50000,  total_sum = 51500

month: 6, roundlot = 26, d_sum = 2600
total_sum = 52000,  total_sum = 52100

month: 7, roundlot = 28, d_sum = 2800
total_sum = 56000,  total_sum = 56900

month: 8, roundlot = 29, d_sum = 2900
total_sum = 58000,  total_sum = 59800

month: 9, roundlot = 30, d_sum = 3000
total_sum = 60000,  total_sum = 60800

month: 10, roundlot = 32, d_sum = 3200
total_sum = 64000,  total_sum = 64000

month: 11, roundlot = 34, d_sum = 3400
total_sum = 68000,  total_sum = 69400

month: 12, roundlot = 35, d_sum = 3500
total_sum = 70000,  total_sum = 70900

month: 13, roundlot = 37, d_sum = 3700
total_sum = 74000,  total_sum = 74600

month: 14, roundlot = 39, d_sum = 3900
total_sum = 78000,  total_sum = 78500

month: 15, roundlot = 41, d_sum = 4100
total_sum = 82000,  total_sum = 82600

month: 16, roundlot = 43, d_sum = 4300
total_sum = 86000,  total_sum = 86900

month: 17, roundlot = 45, d_sum = 4500
total_sum = 90000,  total_sum = 91400

month: 18, roundlot = 47, d_sum = 4700
total_sum = 94000,  total_sum = 94100

month: 19, roundlot = 50, d_sum = 5000
total_sum = 100000,  total_sum = 101100

month: 20, roundlot = 52, d_sum = 5200
total_sum = 104000,  total_sum = 104300

month: 21, roundlot = 55, d_sum = 5500
total_sum = 110000,  total_sum = 111800

month: 22, roundlot = 57, d_sum = 5700
total_sum = 114000,  total_sum = 115500

month: 23, roundlot = 60, d_sum = 6000
total_sum = 120000,  total_sum = 121500

month: 24, roundlot = 63, d_sum = 6300
total_sum = 126000,  total_sum = 127800

month: 25, roundlot = 66, d_sum = 6600
total_sum = 132000,  total_sum = 132400

month: 26, roundlot = 70, d_sum = 7000
total_sum = 140000,  total_sum = 141400

month: 27, roundlot = 73, d_sum = 7300
total_sum = 146000,  total_sum = 146700

month: 28, roundlot = 77, d_sum = 7700
total_sum = 154000,  total_sum = 154400

month: 29, roundlot = 81, d_sum = 8100
total_sum = 162000,  total_sum = 162500

month: 30, roundlot = 85, d_sum = 8500
total_sum = 170000,  total_sum = 171000

month: 31, roundlot = 89, d_sum = 8900
total_sum = 178000,  total_sum = 179900

month: 32, roundlot = 93, d_sum = 9300
total_sum = 186000,  total_sum = 187200

month: 33, roundlot = 98, d_sum = 9800
total_sum = 196000,  total_sum = 197000

month: 34, roundlot = 103, d_sum = 10300
total_sum = 206000,  total_sum = 207300

month: 35, roundlot = 108, d_sum = 10800
total_sum = 216000,  total_sum = 216100

month: 36, roundlot = 114, d_sum = 11400
total_sum = 228000,  total_sum = 229500

标签:突发奇想,指数,int,股票,sum,month,2000,roundlot,total
From: https://www.cnblogs.com/yangsail/p/18327563

相关文章