承接前題:房價 200 萬,年漲 10%;軟工年薪 40 萬,年漲 5%。每年薪資累積 vs 房價成長,模擬幾年後存款 ≥ 房價。關鍵:薪資與房價皆為複利成長,薪資累積為等比級數求和。
begin_value = 200,年增率 rate = 0.1。salary = 40,年增率 rate_salary = 0.05。#include <stdio.h>
int main() {
int i=0;
float salary=40, house=200, rate=0.1, rate_sal=0.05, savings=0;
house = house * (1+rate); // 第1年漲價後
savings = salary; // 第1年薪資
while (savings < house) {
i++;
house *= (1+rate);
salary *= (1+rate_sal);
savings += salary;
}
printf("經過%d年後可買房!\n", i);
return 0;
}

房價增長率 > 薪資增長率,且薪資需累積,導致買房年限極長或永不可及,反映真實社會買房難題。