c语言程序设计精髓 第4周编程题在线测试

###1分数比较(4分)
题目内容:

利用人工方式比较分数大小的最常见的方法是:对分数进行通分后比较分子的大小。请编程模拟手工比较两个分数的大小。首先输入两个分数分子分母的值,例如"11/13,17/19",比较分数大小后输出相应的提示信息。例如,第一个分数11/13小于第二个分数17/19,则输出"11/13<17/19"。

程序的运行结果示例1:

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

11/13<17/19

程序的运行结果示例2:

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

17/19>23/27

程序的运行结果示例3:

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

3/4=18/24

输入提示信息:“Input a/b, c/d:” (注意:逗号后面有一个空格)

输入格式: “%d/%d,%d/%d”

输出格式:

比较的结果是大于:“%d/%d>%d/%d\n”

比较的结果是小于:“%d/%d<%d/%d\n”

比较的结果是相等:“%d/%d=%d/%d\n”

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

存款利率计算器v2.0

在这里插入图片描述

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

存款利率计算器v3.0

在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    double capital,deposit,rate;
    int year,flag=1;
    char a;
    //float deposit;
    printf("Input capital, year:");
    scanf("%lf,%d",&capital,&year);
    if(year == 1){
        rate = 0.0225;
    }else if(year == 2){
        rate = 0.0243;
    }else if(year == 3){
        rate = 0.0270;
    }else if(year == 5){
        rate = 0.0288;
    }else if(year == 8){
        rate = 0.0300;
    }else{
        flag = 0;
    }

    printf("Compound interest (Y/N)?");
    scanf(" %c" ,&a);
    if(a == 'Y' || a == 'y'){
        deposit = capital * pow((1+rate),year);
    }
    if(a == 'N' || a == 'n'){
        deposit = capital * (1 + rate * year);
    }
    if(flag){
        printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
    }else{
        printf("Error year!\n");
    }

}

4博弈论之Best Response(6分)

题目内容:

在博弈论中,有一种决策称为Best Response,通俗的意思就是选择一种策略使得团体利益最大化。C语言学习成绩的评定方式分为两种,一种是自由刷题模式(compete),没有固定标准,刷题越多者排名越靠前,其期末分数越高;另一种是规定每个人必须做够多少道题(standard),达到要求就能取得相应分数。

假设一个班级中的学生分为A、B两类,A类同学学习热情很高,乐于做题,采用compete模式可以获得成就感并且在期末拿到高分,compete模式可以让他们有10分的收益;采用standard模式他们也可以在期末拿到高分,但不能满足他们的求知欲,standard模式可以让他们有8分的收益。B类同学仅仅希望期末拿高分,如果采用compete模式,他们竞争不过A类同学,期末成绩不理想,因此compete模式能给他们6分的收益;如果采用standard模式,他们可以完成规定任务并拿到高分,因此standard模式可以让他们有10分的收益。

编程输入A类和B类同学分别占班级总人数的百分比,分别计算并输出采用compete和standard两种刷题模式下的全班总收益,并输出这个班级在这场博弈中的Best Response是哪种模式。

注: 程序中使用的数据类型为float

程序运行结果示例1:

Input percent of A and B:0.2 0.8↙

compete = 6.8000

standard = 9.6000

The Best Response is standard!

程序运行结果示例2:

Input percent of A and B:0.8 0.2↙

compete = 9.2000

standard = 8.4000

The Best Response is compete!

程序运行结果示例3:

Input percent of A and B:0.5 0.5↙

compete = 8.0000

standard = 9.0000

The Best Response is standard!

输入提示信息:“Input percent of A and B:”

输入格式: “%f%f”

输出格式:“compete = %.4f\nstandard = %.4f\n”

输出提示信息:“The Best Response is compete!”

输出提示信息:“The Best Response is standard!”

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    float a,b,c,s;
    printf("Input percent of A and B:");
    scanf("%f%f",&a,&b);
    c = a * 10 + b * 6;
    s = a * 8 + b * 10;
    printf("compete = %.4f\nstandard = %.4f\n",c,s);
    if(c > s){
        printf("The Best Response is compete!");
    }else{
        printf("The Best Response is standard!");
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在博弈论中,有一种决策称为Best Response,通俗的意思就是选择一种策略使得团体利益最大化。C语言学习成绩的评定方式分为两种,一种是自由刷题模式(compete),没有固定标准,刷题越多者排名越靠前,其期末分数越高;另一种是规定每个人必须做够多少道题(standard),达到要求就能取得相应分数。 假设一个班级中的学生分为A、B两类,A类同学学习热情很高,乐于做题,采用compete模式可以获得成就感并且在期末拿到高分,compete模式可以让他们有10分的收益;采用standard模式他们也可以在期末拿到高分,但不能满足他们的求知欲,standard模式可以让他们有8分的收益。B类同学仅仅希望期末拿高分,如果采用compete模式,他们竞争不过A类同学,期末成绩不理想,因此compete模式能给他们6分的收益;如果采用standard模式,他们可以完成规定任务并拿到高分,因此standard模式可以让他们有10分的收益。 编程输入A类和B类同学分别占班级总人数的百分比,分别计算并输出采用compete和standard两种刷题模式下的全班总收益,并输出这个班级在这场博弈中的Best Response是哪种模式。 【注】程序中使用的数据类型为float 程序运行结果示例1: Input percent of A and B:0.2 0.8↙ compete = 6.8000 standard = 9.6000 The Best Response is standard! 程序运行结果示例2: Input percent of A and B:0.8 0.2↙ compete = 9.2000 standard = 8.4000 The Best Response is compete! 程序运行结果示例3: Input percent of A and B:0.5 0.5↙ compete = 8.0000 standard = 9.0000 The Best Response is standard! 输入提示信息:"Input percent of A and B:" 输入格式:"%f%f" 输出格式:"compete = %.4f\nstandard = %.4f\n" 输出提示信息:"The Best Response is compete!" 输出提示信息:"The Best Response is standard!"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值