CPrimer Plus 学习(第六章)
程序员文章站
2023-12-22 23:05:52
...
Daphne 以10%的单利息投资了100美元(每年投资赢得的利息为原始投资10%)。Deirdre 以每年5%的符合利息投资了100美元(每年利息是当前结余的5%)编写程序计算多少年Deirdre 投资额超过Daphne,并显示那时两人投资额。
#include<stdio.h>
int main()
{
float m_Da, m_De;
int year;
m_Da = m_De = 100;
for(year = 0; m_De <= m_Da; year++)
{
m_De *= 1.05;
m_Da += 10;
}
printf("After %d years, Deirdre will exceed Daphne\n", year);
printf("Deirdre will have $%lf\n", m_De);
printf("Daphne will have $%lf\n", m_Da);
}