问一个C语言程序
已知银行整存整取存款不同期限的月息利率分别为:
月利息率为:期限一年0.63%,两年0.66%,三年0.69%,五年0.75%,8年0.84%,要求输入存钱的本金和期限,求到期时能得到的利息与本金的合计?谢谢哦
参考答案:算不算复利?
main()
{
const double rate[] = {0.0063, 0.0066, 0.0069, 0.0075, 0.0084};
int years = 0;
float init = 0;
double sum = 0;
printf("\nInput initial amount of money:");
scanf("%f", &init);
printf("\nType in save period in years:");
scanf("%d", &years);
if( years==1 || years==2 || years == 3 || years == 5 || years == 8)
{
if(years==1)
sum = init*(1+rate[0]*12*years);
else if(years==2)
sum = init*(1+rate[1]*12*years);
else if(years==3)
sum = init*(1+rate[2]*12*years);
else if(years==5)
sum = init*(1+rate[3]*12*years);
else
sum = init*(1+rate[4]*12*years);
printf("\nTotal amount after %d years: %.2f\n", years, sum);
}
else
{
printf("\nWrong number, Please type in years again: ");
scanf("%d", &years);
}
}