C语言寒假大作战03

格式

表格

|问题|答案
|:--|--😐:--:
| 这个作业属于那个课程 |https://edu.cnblogs.com/campus/zswxy/CST2019-2
|这个作业要求在哪里 |https://edu.cnblogs.com/campus/zswxy/CST2019-2/homework/10271
|我在这个课程的目标是 | 使用rand()函数,增加各年级题目操作函数
|作业正文|https://i-beta.cnblogs.com/posts/edit
|参考文献|随机数rand

2.1.1内容

使用自定义函数、switch语句来完成菜单程序。

2.2.2 设计思路和遇到的问题

(1).设计思路
在原有基础上增加rand函数来增加一,二,三年级的题目数量;使之每个年级增加到十个数学计算。
(2).遇到的问题
就是新添加的rand函数有所不了解,然后查了资料并翻阅了书本,才能理解如何运用它。

2.2.3 程序结果截图



2.2.4 程序代码

1.1.1数据处理

#include<stdio.h>
    int help(int opt) {

#include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    int help(int opt) {
printf("\n操作列表:\n    1)一年级    2)二年级    3)三年级\n     4)帮助     5)退出程序\n");
printf("请输入操作: > 10 \n\n\n");
return 0;
   }

    void operation1(int opt) {
int i,op;
for(i=0; i<10; i++) {
	int divisor1=rand()%10;
	int divisor2=rand()%10;
	char ops[2]= {'+','-'};
	op=rand()%2;

	printf("%d %c %d=__\n",divisor1,ops[op],divisor2);
    }
        }

    void operation2(int opt) {
int i,op;
for(i=0; i<10; i++) {
	int divisor1=rand()%101;
	int divisor2=rand()%101;
	char ops[2]= {'*','/'};
	op=rand()%2;

	if(divisor2==0)printf("%2d * %2d=__\n",divisor1,divisor2);
	else printf("%2d %c %2d=__\n",divisor1,ops[op],divisor2);
     }
         }

    void operation3(int opt) {
int i,op1,op2,op3;
for(i=0; i<10; i++) {
	int divisor1=rand()%101;
	int divisor2=rand()%101;
	int divisor3=rand()%101;
	char operator1[4]= {'+','-','*','/'};
	char operator2[3]= {'+','-','*'};
	op1=rand()%4;
	op2=rand()%3;
	op3=rand()%4;

	if((divisor2==0)&&(divisor3!=0))printf("%2d %c %2d %c %2d=__\n",divisor1,operator2[op2],divisor2,operator1[op1],divisor3);
	else if((divisor2!=0)&&(divisor3==0))printf("%2d %c %2d %c %2d=__\n",divisor1,operator1[op1],divisor2,operator2[op2],divisor3);
	printf("%2d %c %2d %c %2d=__\n",divisor1,operator1[op1],divisor2,operator1[op3],divisor3);
     }
         }

    int error(int opt) {
printf("Error!!!\n错误操作指令, 请重新输入");
return 0;
         }

    int main() {
printf("========== 口算生成器 ==========\n");
printf("欢迎使用口算生成器 :\n \n \n帮助信息\n您需要输入命令代号来进行操作, 且\n");
printf("一年级题目为不超过十位的加减法;\n二年级题目为不超过百位的乘除法;\n三年级题目为不超过百位的加减乘除混合题目.\n\n\n");

int opt=-1;

while(opt!=0) {
	help(opt);
	scanf("%d",&opt);

	switch(opt) {
		case 1:
			operation1(opt);
			break;
		case 2:
			operation2(opt);
			break;
		case 3:
			operation3(opt);
			break;
		default :
			error(opt);
			break;
	}
        }
         return 0;
            }

2.2.5 Gitee上传截图与链接


2.2.6 Gitee上传截图与链接


posted @ 2020-02-11 16:16  天天搞博客  阅读(231)  评论(0编辑  收藏  举报