/*15. Daphne 以 10%的单利息投资了 100 美元(也就是说,每年投资赢得的利息等于原始投资的 10%)。
Deirdre 则以每年 5%的复合利息投资了 10O 美元(也就是说,利息是当前结余的 5%,其中包括以前的利息)。
编写一个程序,计算需要多少年 Deirdre 的投资额才会超过 Daphne,并且显示出到那时两个人的投资额。*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int year = 0;
double Da = 100, De = 100;
while (Da >= De)
{
Da = Da + 100 * 0.1;
De = De + De * 0.05;
year++;
}
printf("After %d years,Deirdre's investment is %lf,Daphne's investment is %lf\n",year,De,Da);
system("pause");
return 0;
}
C Primer Plus6-15
最新推荐文章于 2016-01-27 17:18:08 发布