# 2020年哈尔滨工业大学C语言程序设计精髓 第四周编程题

/本文为原创内容，C语言练习试题适用参考学习，因为全为自己编写可能没有按照标准答案或者含有使可读性减少的步骤，有不对的地方希望各位指出/

1

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>
#include<math.h>
int main()
{
int a,b,c,d;
float num1,num2;
printf("Input a/b, c/d:");
scanf("%d/%d,%d/%d",&a,&b,&c,&d);
num1=(float)a/b;
num2=(float)c/d;
if(num1>num2)
{
printf("%d/%d>%d/%d\n",a,b,c,d);
}
else if(num1<num2)
{
printf("%d/%d<%d/%d\n",a,b,c,d);
}
else
{
printf("%d/%d=%d/%d\n",a,b,c,d);
}
return 0;
}

2

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

“%lf,%d,%lf”

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

3

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!

%.4f\n”

#include <stdio.h>
#include <math.h>
int main()
{
int year;
double capital,rate;
char choose;
printf("Input capital, year:");
scanf("%lf,%d", &capital, &year );
printf("Compound interest (Y/N)?");
scanf(" %c",&choose);
switch(year)
{
case 1: rate = 0.0225;    break;
case 2: rate = 0.0243;    break;
case 3: rate = 0.0270;    break;
case 5: rate = 0.0288;    break;
case 8: rate = 0.0300;    break;
default: rate = 0;        break;
}
if (rate != 0 )
{
if ( choose == 'Y' || choose == 'y' )
printf("rate = %.4f, deposit = %.4f\n", rate,capital * pow((1+rate), year));
if ( choose == 'N' || choose == 'n' )
printf("rate = %.4f, deposit = %.4f\n", rate,capital * (1 + rate * year));
}
else
{
printf("Error year!\n");
}
return 0;
}

4

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!

B:”

%.4f\n”

compete!”

standard!”

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

04-17
10-09
03-04 3017
11-24 7106
02-19 4215
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林