月还款额计算公式的编程题
发布网友
发布时间:2022-04-23 05:26
我来回答
共1个回答
热心网友
时间:2023-10-16 08:45
#include<iostream>
using namespace std;
double cal_power(double x,int n)
{
if(n>1)return x*cal_power(x,n-1);
else return x;
}
double cal_money(double loan,double rate,int month)
{
return loan*cal_power(1+rate,month)/(double)month;
}
int main()
{
double loan,rate;
cin>>loan>>rate;
for(int i=5;i<=30;i++)
cout<<i<<"-"<<cal_money(loan,rate,i*12)<<endl;
return 0;
}
int fact(int n)
{
if(n>1)return n*fact(n-1);
else return 1;
}
int cal(int m,int n)
{
if(n>1)return n+cal(m,n-1);
else return m;
}
void main()
{
int n;
cin>>n;
cout<<cal(1,n)/(double)fact(n)<<endl;
}