# 慕课哈工大c语言程序设计精髓第4周编程题在线测试

19 篇文章 31 订阅

### 1分数比较

#include <stdio.h>
#include <stdlib.h>
int main()
{
int a1,a2,b1,b2;
printf("Input a/b, c/d:");
scanf("%d/%d,%d/%d",&a1,&a2,&b1,&b2);
if(a1*b2>a2*b1)
{
printf("%d/%d>%d/%d\n",a1,a2,b1,b2);
}
else if(a1*b2<a2*b1)
{
printf("%d/%d<%d/%d\n",a1,a2,b1,b2);
}
else printf("%d/%d=%d/%d\n",a1,a2,b1,b2);
return 0;
}


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

### 2存款利率计算器v2.0

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

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

• 按普通计息方式计算本利之和的公式为：deposit  =  capital  * (1 + rate * n)

#include <stdio.h>
#include <stdlib.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;
}


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

### 3存款利率计算器v3.0

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

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

deposit  =  capital  * (1 + rate * n)

#include <stdio.h>
#include <stdlib.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;
}


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!

### 4博弈论之Best Response

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;
}


05-18 161
03-26 1994
05-17 292
11-24 1万+
05-14 1384
11-12 6123
11-09 8212
05-07 1万+
05-17 315

a13298411797

¥2 ¥4 ¥6 ¥10 ¥20

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