首页 > 试题广场 >

Daphne以10%的单利投资了100美元。也就是说,每一年

[问答题]
Daphne以10%的单利投资了100美元。也就是说,每一年的利润都是投资额的10%,即每年10美元:
利息=0.10x原始存款
而Cleo以5%的复利投资了100美元。也就是说,利息是当前存款(包括获得的利息)的5%:
利息=0.05x当前存款
Celo在第一年投资100美元的盈利是5%——得到了105美元。下一年的盈利是105美元的5%——即5.25美元,依此类推。请编写一个程序,计算多少年,Cleo的投资价值才能超过Daphne的投资价值,并显示此时两个人的投资价值。
#include <iostream>
using namespace std;

int main()
{
    cout<<"此程序用来比较多少年后两个人的投资价值相等"<<endl;
    double a=100;
    const double b=0.1;
    const double c=0.05;
    int i;
    double fun1=a*b+100,fun2=(c+1)*100;
    for(i=2;fun2<=fun1;i++)
    {
        //cout<<fun1<<"  "<<fun2<<endl;
        fun1=a*b+fun1;
        fun2=(c+1)*fun2;
    }
    cout<<"开始超过的年份为:"<<i<<endl
        <<"此时第一个人的钱为:"<<fun1<<endl
        <<"此时第二个人的钱为:"<<fun2<<endl;
    system("pause");
    return 0;
发表于 2019-10-11 08:47:53 回复(0)
#include <iostream>
using namespace std;
int main()
{
int money_D = 100,year = 1;
float money_C = 100.00;
while ( money_C <= money_D )
{
money_D += 10;
money_C *= (1+0.05);
year++;
}
cout << "在第" << year << "年,Cleo的投资超过Daphne的投资" << endl;
cout << "此时Daphne的投资价值为:" << money_D << " 美元" << endl;
cout << "此时Cleo的投资价值为:" << money_C << " 美元" << endl;
return 0;
}
编辑于 2019-08-05 11:32:07 回复(0)
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
    int year=0, Daphne, Cleo;
    float a = 100, b = 100;
    do
    {    Daphne = a*(1+0.1*year);
        Cleo = b*pow(1.05,year);
        year++;
    }
    while (Daphne >= Cleo);
        cout << "need " << year << " years" << endl;
        cout << "In " << year << " year: " << endl;
        cout << "Daphne has " << Daphne << " dollars" << endl;
        cout << "Cleo has " << Cleo << " dollars" << endl;
}

发表于 2019-04-29 16:49:19 回复(0)
#include <stdio.h>
int main(int argc,const char *argv[])
{
    int year=1,Dephne=100;
    float Celo=100;
    while(Daphne>=Celo)
    {
        Daphne=100+10*year;
       Celo=Celo*1.05;
        year++;  
    }
    printf("Daphne:%d,Celo:%.2f,year:%d",Daphne,Celo,(year-1));
}

编辑于 2019-04-01 13:01:44 回复(0)
double sumi = 0.0, sumj = 0.0; 
 int n = 0; 
 for (; sumj <= sumi;++n){
  sumi = 100+10 * n; 
  sumj = 100*pow(1.05, n);
 }
 cout << "year: " << n << "dap:" << sumi << "cle:" << sumj << endl;
编辑于 2019-03-22 15:43:21 回复(2)