动动手0.#include <stdio.h>
float Si = 0; //Single interest
float Ci = 0; //Compound interest
int years = 1;
float F = 0, N = 0; //fish, night
float F_P = 10000.00, N_P = 10000.00; // Principal
float F_rate = 0.10, N_rate = 0.05;
int main()
{
do
{
N_P = N_P + Ci;
Ci = N_P * N_rate;
Si = (F_P * F_rate);
F = F_P + years * Si;
N = N_P + Ci;
N = N_P + Ci;
if(N > F)
{
break;
}
years++;
}
while(F > N);
printf("%d years later, fish's investment will exceed night!\n", years);
printf("fish's investment amount are: %.2f\n", F);
printf("night's investment amount are: %.2f\n", N);
return 0;
}
1.#include <stdio.h>
float principal = 4000000;
float interest = 0;
int years = 0;
int main()
{
do
{
principal -= 500000;
interest = principal * 0.08;
principal = principal + interest;
years++;
}
while(principal > 0);
printf("%d\n ", years);
return 0;
}
|