C语言函数计算贷款年利率 c语言年利率代码怎么写

C语言计算年利率 这题怎么写?分情况讨论即可,具体代码如下:
#include stdio.h
int main() {
float r = 7.7; // 基本年利率
int n;
scanf("%d", n);
if (n = 0)
printf("error\n");
else if (n == 1) // 1年内
printf("实际利率=%.2f%%\n", r * 0.5);
else if (n = 3) // 3年内
printf("实际利率=%.2f%%\n", r * 0.7);
else if (n = 5) // 5年内
printf("实际利率=%.1f%%\n", r);
else// 5年以上
printf("实际利率=%.2f%%\n", r * 1.1);
return 0;
}
运行结果如下:
符合样例输出,望采纳~
c语言计算银行利息#include stdio.h
#include math.h
int main(){
setbuf(stdout,NULL);//eclipse 需要加这段, 不然运行后看不到输出
float sum, money, year, rate;
printf("input money \n");//等待用户输入存款金额, 回车键结束.
scanf("%f", money);//赋值给变量 money
printf("input year \n");//等待用户输入存款期限, 回车键结束.
scanf("%f", year);//赋值给变量 year
printf("input rate \n");//等待用户输入年利率, 回车键结束.
scanf("%f", rate);//赋值给变量 rate
sum = money * pow(1 + rate, year); //pow函数
printf("sum= %.2f" , sum);//输出本息, 保留小数点后两位
return 0;
}
C++ C语言程序设计 题目:贷款计算器/*
* main.c
*
*Created on: 2011-6-8
*Author: icelights
*/
#include stdio.h
#include stdlib.h
#include ctype.h
#include math.h
#define APR10.0747/*1年(含1年)年利率*/
#define APR20.0756/*1-3年(含3年)年利率*/
#define APR30.0774/*3-5年(含5年)年利率*/
#define APR40.0783/*5年以上年利率*/
#define A_TO_M1/12/*月利率 = 年利率 / 12*/
#define RTP12/*Reimbursement total periods还款总期数 =年限*12*/
#define LENGTH80
struct LoanInfo
{
/*姓名*/
charname[LENGTH];
/*贷款总额*/
doubleLoanAmount;
/*贷款年限*/
doubleLoanYear;
/*月付*/
doubleMonthlyPayment;
/*总利息*/
doubleTotalInterest;
/*还款总额*/
doubleReimbursementAmount;
/*年利率*/
doubleapr;
struct LoanInfo *next;
};
void CalcShow(struct LoanInfo * cur, struct LoanInfo * hd,
struct LoanInfo * prv);
int main(void)
{
int temp;
struct LoanInfo * head = NULL;
struct LoanInfo * prev, * current;
current = (struct LoanInfo *)malloc(sizeof(struct LoanInfo));
if (NULL == head)
{
head = current;
}
else
{
prev-next = current;
}/*End of if (NULL == head)*/
puts("请输入姓名");
gets(current-name);
fflush(stdin);
puts("请输入贷款数额(单位:万元)");
scanf("%lf", ¤t-LoanAmount);
fflush(stdin);
puts("请输入贷款年限");
scanf("%lf", ¤t-LoanYear);
fflush(stdin);
printf("姓名:%s,贷款年限:%lf, 贷款数额%lf",
current-name, current-LoanYear, current-LoanAmount);
prev = current;
puts("请确认Y/N");
temp = getchar();
switch(toupper(temp))
{
case 'Y':CalcShow(current, head, prev);
break;
case 'N':free(current);
main();
break;
default:puts("输入错误");
free(current);
break;
}
return 0;
}
void CalcShow(struct LoanInfo * cur, struct LoanInfo * hd,
struct LoanInfo * prv)
{
char lcv_temp;
if (cur-LoanYear = 1)
cur-apr = APR1;
else if (cur-LoanYear = 3)
cur-apr = APR2;
else if (cur-LoanYear = 5)
cur-apr = APR3;
else
cur-apr = APR4;
/*End of if (year = 1)*/
cur-LoanAmount = 10000 * cur-LoanAmount;
cur-ReimbursementAmount = cur-LoanAmount * pow((1 + cur-apr), cur-LoanYear);

推荐阅读