题目:Daphne以10%的单利息投资了100美元。Deirdre以每年5%的复利息投资了100美元。编写一个程序,计算需要多少年Deirdre的投资额才会超过Daphne,并显示出到那时两个人的投资额。
//6-15
#include<stdio.h>
#define CAPITAL 100
#define RATE_DA 0.1
#define RATE_DE 0.05
int main(void)
{
int year;
float money_Da=CAPITAL;
float money_De=CAPITAL;
for(year=0;money_De<=money_Da;year++){
money_Da+=CAPITAL*RATE_DA;
money_De*=1+RATE_DE;
}
printf("%d\n",year);
printf("Daphne will have %.2f $.\n",money_Da);
printf("Deirdre will have %.2f $.\n",money_De);
return 0;
}