# c语言程序设计精髓第四章编程题

c语言 专栏收录该内容
83 篇文章 19 订阅

### 1 分数比较（4分）

Input a/b, c/d:11/13,17/19↙

11/13<17/19

Input a/b, c/d:17/19,23/27↙

17/19>23/27

Input a/b, c/d:3/4,18/24↙

3/4=18/24

#include<stdio.h>
int main()
{
int fz1,fz2,fm1,fm2;
printf("Input a/b, c/d:");
scanf("%d/%d,%d/%d",&fz1,&fm1,&fz2,&fm2);
if ((float)fz1/fm1 > (float)fz2/fm2 )
printf("%d/%d>%d/%d\n",fz1,fm1,fz2,fm2);
else if ((float)fz1/fm1 < (float)fz2/fm2 )
printf("%d/%d<%d/%d\n",fz1,fm1,fz2,fm2);
else printf("%d/%d=%d/%d\n",fz1,fm1,fz2,fm2);

return 0;
}

### 2 存款利率计算器v2.0（4分）

设capital是最初的存款总额（即本金），rate是整存整取的存款年利率，n 是储蓄的年份，deposit是第n年年底账号里的存款总额。已知如下两种本利之和的计算方式：

• 按复利方式计息的本利之和计算公式为：

• 按普通计息方式计算本利之和的公式为：

deposit  =  capital  * (1 + rate * n)

编程从键盘输入存钱的本金、存款期限以及年利率，然后再输入按何种方式计息，最后再计算并输出到期时能从银行得到的本利之和，要求结果保留到小数点后4位。

Input rate, year, capital:0.0225,2,10000↙

Compound interest (Y/N)?Y

deposit = 10455.0625

Input rate, year, capital:0.0225,2,10000↙

Compound interest (Y/N)?n

deposit = 10450.0000

#include <stdio.h>
#include <math.h>
int main()
{
int year;
double mon,rate;
char choice;
printf("Input rate, year, capital:");
scanf("%lf,%d,%lf",&rate,&year,&mon);
printf("Compound interest (Y/N)?");
scanf(" %c",&choice);
if(choice=='y' || choice=='Y')
{
printf("deposit = %.4f\n",mon*pow((1+rate),year));
}
else printf("deposit = %.4f\n",mon*(1+rate*year));
return 0;
}

### 3 存款利率计算器v3.0（9分）

• 按复利方式计息的本利之和计算公式为：

• 按普通计息方式计算本利之和的公式为：

deposit  =  capital  * (1 + rate * n)

Input capital, year:10000,2↙

Compound interest (Y/N)?Y↙

rate = 0.0243, deposit = 10491.9049

Input capital, year:10000,2↙

Compound interest (Y/N)?n↙

rate = 0.0243, deposit = 10486.0000

Input capital, year:1000,4↙

Compound interest (Y/N)?y↙

Error year!

#include <stdio.h>
#include <math.h>
int main()
{
int year;
double mon,rate;
char choice;
printf("Input capital, year:");
scanf("%lf,%d",&mon,&year);
printf("Compound interest (Y/N)?");
scanf(" %c",&choice);
if(choice=='y' || choice=='Y')
{
switch(year)
{
case 1:
rate=0.0225;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*pow((1+rate),year));
break;
case 2:
rate=0.0243;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*pow((1+rate),year));
break;

case 3:
rate=0.0270;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*pow((1+rate),year));
break;

case 5:
rate=0.0288;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*pow((1+rate),year));
break;

case 8:
rate=0.0300;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*pow((1+rate),year));
break;
default:
printf("Error year!\n");
break;
}
}
else
{switch(year)
{
case 1:
rate=0.0225;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*(1+rate*year));
break;
case 2:
rate=0.0243;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*(1+rate*year));
break;

case 3:
rate=0.0270;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*(1+rate*year));
break;

case 5:
rate=0.0288;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*(1+rate*year));
break;

case 8:
rate=0.0300;
printf("rate = %.4f, deposit = %.4f\n",rate,mon*(1+rate*year));
break;
default:
printf("Error year!\n");
break;
}
}
return 0;
}

### 4 博弈论之Best Response（6分）

Input percent of A and B:0.2 0.8↙

compete = 6.8000

standard = 9.6000

The Best Response is standard!

Input percent of A and B:0.8 0.2↙

compete = 9.2000

standard = 8.4000

The Best Response is compete!

Input percent of A and B:0.5 0.5↙

compete = 8.0000

standard = 9.0000

The Best Response is standard!

#include <stdio.h>
int main()
{
float a,b,com,sta;
printf("Input percent of A and B:");
scanf("%f%f",&a,&b);
com=10*a+6*b;
sta=8*a+10*b;
printf("compete = %.4f\nstandard = %.4f\n",com,sta);
if(com>sta)
{
printf("The Best Response is compete!");
}
else printf("The Best Response is standard!");
return 0;
}

• 7
点赞
• 0
评论
• 26
收藏
• 打赏
• 扫一扫，分享海报

02-16 130
05-17 292
11-09 8212
05-14 3832
04-07 637
05-18 161
05-07 7012
05-17 315
05-31 2万+
05-08 1万+
05-30 893
03-06 539
11-12 6123

suxiaorui

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。