百题大战c语言写九九乘法表,C语言寒假大作战04

1. 题目介绍

前面我们我们已经将口算题的生成程序给写完了,现在呢,我想要给题目后面加上答案(ps: 哎哎哎,计算器不香嘛)

我们仍然是 随机!!!!!! 生成口算题 ,但是我们还需要再原本 ___ 的横线上加上答案

这里我们规定如下格式:

/*----- 一年级 -----*/

8 + 5 = 13

0 - 3 = -3

7 - 0 = 7

1 - 6 = -5

4 - 4 = 0

ps:请注意这里的答案格式为两字符占位 _ + _ = __

/*----- 二年级 -----*/

5 / 6 = 0.833333

5 * 6 = 30

9 * 2 = 18

3 / 2 = 1.5

7 * 3 = 21

ps: 九九乘法表还记得嘛 滑稽 :)

/*----- 三年级 -----*/

79 - 20 / 50 = 78.6

99 * 29 * 31 = 89001

16 / 18 + 20 = 20.8889

39 * 44 / 33 = 52

35 - 79 - 27 = -71

ps:请注意这里的格式为两字符占位 __ + __ + __ =

注意 '/' 除号后面不能为0哦

2. 本次作业

2.1 题目内容与要求

9445e8f1c1506557bd4fcac6e29bfa09.png

2.1.1 菜单程序函数调用图如下:

66435f2c31463bb9b061f9d941a9c645.png

2.1.2 程序截图:

e0dcd1aea2b3c8f9eb514189422090a0.png

d764544019c4474de27c738eb3dd8253.png

9b6e64e9fc91d8038f41a292de169c5a.png

99cffe5f6f7c423ccfdb75d8c66cf6ea.png

c1b995847213bdaa12ea344a955274c8.png

ad89f4de03b60624c3cc0c494f08abe0.png

2.2 提交内容

本次作业统一标题:C语言寒假大作战02Deadline: 2020/02/12 20:00pm

2.2.1 作业头:

为了方便其他学校的老师或者助教了解课程实况,请大家在作业开头添加格式描述:

这个作业属于哪个课程

这个作业的目标

前面我们我们已经将口算题的生成程序给写完了,现在呢,我想要给题目后面加上答案(ps: 哎哎哎,计算器不香嘛)

我们仍然是 随机!!!!!! 生成口算题 ,但是我们还需要再原本 ___ 的横线上加上答案

作业正文

使用switch编写菜单程序,使用rand函数来产生随机数,并算出生成口算题的结果

2.2.2 设计思路和遇到的问题

开始动手的时候不知道为什么总是没有结果,反复测试有没有用,最后只能重新再打一次

2.2.3 程序结果截图

84c6368a242a68c24273d2dc336e04d7.png

d66258545c1f8b4dfa206ae5bb8c7609.png

3712200821f685e3bd5a0f4996bc130a.png

ff032058fa4271ad1dc135302628ac07.png

2.2.4 程序代码

需要在题目后面加上题目的答案,且使用上次作业的框架,调用关系如上面思维导图

1 #include

2 #include

3 #include

4 #include

5

6 inthelp();7 intmenu();8 interror();9 intgrade_1();10 intgrade_2();11 intgrade_3();12 double answer(double a, double b, double c, char d, chare);13

14 intmain()15 {16 int grade = 1;17

18 printf("=================================jj口算生成器 ===================================================");19 printf("欢迎使用口算生成器哦,铁子 :)");20 printf("");21

22 help();23 while(grade)24 {25 grade =menu();26

27 switch(grade)28 {29 case 1: grade_1(); break;30 case 2: grade_2(); break;31 case 3: grade_3(); break;32 case 4: help(); break;33 case 5: grade = 0; break;34 default: error(); grade = 1; break;35 }36 }37 printf("程序结束, 欢迎下次使用");38 printf("任意键结束,hh……");39

40 _getch();41 return 0;42 }43

44 inthelp()45 {46 printf("帮助信息:");47 printf("您需要输入命令代号来进行操作, 且");48 printf("一年级题目为不超过十位的加减法;");49 printf("二年级题目为不超过百位的乘除法;");50 printf("三年级题目为不超过百位的加减乘除混合题目.");51 printf("");52 }53

54 intmenu()55 {56 int a = 0;57 printf("操作列表:");58 printf("1)一年级 2)二年级 3)三年级");59 printf("4)帮助 5)退出程序");60 printf("请输入操作>");61 scanf("%d", &a);62 printf("< 执行操作 :)");63 printf("");64 returna;65 }66

67 interror()68 {69 printf("Error!!!报错");70 printf("错误操作, 重新输入,老铁");71 printf("");72 }73

74 intgrade_1()75 {76 printf("gkd,gkd,现在是一年级题目");77 printf("请输入你他妈所需要的题目个数>");78 int num = 0;79 scanf("%d", &num);80 printf("< 执行操作 :)");81

82 inta, b, c;83 srand((unsigned)time(NULL));84

85 printf("/*----- 一年级 -----*/");86

87 for (int i = 0; i < num; i++)88 {89 a = rand() % 10;90 b = rand() % 10;91 c = rand() % 2;92 if (c == 0)93 {94 printf("%d + %d = %d", a, b, a +b);95 }96 else

97 {98 printf("%d - %d = %d", a, b, a -b);99 }100 }101 }102

103 intgrade_2()104 {105 printf("现在是二年级题目,孩子:");106 printf("你要几个题目");107 int num = 0;108 scanf("%d", &num);109 printf("< 执行操作 :)");110

111 doublea, b, c;112 srand((unsigned)time(NULL));113

114 printf("/*----- 二年级 -----*/");115

116 for (int i = 0; i < num; i++)117 {118 a = rand() % 100;119 b = rand() % 100;120 c = rand() % 2;121 if (c == 0)122 {123 printf("%2g * %2g = %g", a, b, a *b);124 }125 else

126 {127 printf("%2g / %2g = %g", a, b + 1, a / (b + 1));128 }129 }130 }131

132 intnum_dividend()133 {134 for (int i = 0; true; i++)135 {136 if (i = rand() % 100)137 returni;138 }139 }140

141 char four_arithmetic(intnum)142 {143 switch(num)144 {145 case 1: return '+';146 case 2: return '-';147 case 3: return '*';148 case 0: return '/';149 }150 }151 intgrade_3()152 {153 printf("卧槽,现在是三年级题目:");154 printf("请随便打一个数");155 int num = 0;156 scanf("%d", &num);157 printf("< 执行操作 :)");158

159 printf("/*----- 三年级 -----*/");160

161 double a = 0, b = 0, c = 0;162 chard, e;163 for (int i = 0; i < num; i++)164 {165 printf("%2g %c %2g %c %2g = %g");166 }167 }168

169 double answer(double a, double b, double c, char d, chare)170 {171 double result = 0;172 if (d == '*' || d == '/')173 {174 switch(d)175 {176 case '*': result = a * b; break;177 case '/': result = a / b; break;178 }179

180 switch(e)181 {182 case '+': return result +c;183 case '-': return result -c;184 case '*': return result *c;185 case '/': return result /c;186 }187 }188 else if (e == '*' || e == '/')189 {190 switch(e)191 {192 case '*': result = b * c; break;193 case '/': result = b / c; break;194 }195

196 switch(d)197 {198 case '+': return a +result;199 case '-': return a -result;200 case '*': return a *result;201 case '/': return a /result;202 }203 }204 else

205 {206 switch(d)207 {208 case '+': result = a + b; break;209 case '-': result = a - b; break;210 }211

212 switch(e)213 {214 case '+': return result +c;215 case '-': return result -c;216 }217 }218 }

2.2.5 Gitee上传截图与链接

4526531eec7c115522db5d149f78aa8b.png

2507a28089f764cee25524518f22bbc9.png

注意你的修改注释

3.参考资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值