1. 表头###
这个作业属于哪个课程 | https://edu.cnblogs.com/campus/zswxy/CST2019-1 |
---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/zswxy/2019TA/homework/10263 |
这个作业的目标 | 学习并掌握基本的git命令 |
其他参考文献 | %g |
2. 作业内容###
2.1 设计思路与问题#####
设置相对应的变量,然后用随机数来给它赋值,在用变量进行计算,输出;
2.2 程序结果截图#####
2.3 程序代码#####
#include<stdio.h>
#include<stdlib.h>
int y;
int i;
int num1, num2, num3, flag, kt;
double result;
char op[4] = { '+','-','*','/' };
void menu()
{
printf("操作列表:
");
printf("1)一年级 2)二年级 3)三年级
");
printf("4)帮助 5)退出程序
");
printf("请输入操作> ");
}
void help()
{
printf("帮助信息:");
printf("
");
printf("你需要输入命令代号来进行操作,且
");
printf("一年级题目为不超过十位的加减法;
");
printf("二年级题目为不超过百位的乘除法;
");
printf("三年级题目为不超过百位的加减乘除混合题目;
");
printf("
");
menu();
}
void error()
{
printf("< 执行操作:)
");
printf("
");
printf("Error!!!
错误操作指令,请重新输入
");
printf("
");
menu();
}
void first_grade()
{
printf("< 执行操作:)
");
printf("现在为一年级题目:
");
printf("输入生成题目数 > ");
scanf("%d", &y);
printf("< 执行操作:)");
operation_1();
}
void second_grade()
{
printf("< 执行操作:)
");
printf("现在为二年级题目:
");
printf("输入生成题目数 > ");
scanf("%d", &y);
printf("< 执行操作:)");
operation_2();
}
void third_grade()
{
printf("< 执行操作:)
");
printf("现在为三年级题目:
");
printf("输入生成题目数 > ");
scanf("%d", &y);
printf("< 执行操作:)");
operation_3();
}
int operation_1()
{
printf("
");
for (i = 0; i < y; i++)
{
num1 = rand() % 10;
num2 = rand() % 10;
flag = rand() % 2;
if (flag == 0)
result = num1 + num2;
else
result = num1 - num2;
printf("%d %c %d = %2.0f
", num1, op[flag], num2, result);
}
printf("
");
menu();
}
int operation_2()
{
printf("
");
for (i = 0; i < y; i++)
{
num1 = rand() % 10;
if (op[(rand() % 2) + 2] == '/')
{
num2 = (rand() % 9) + 1;
result = num1*1.0 / num2*1.0;
printf("%d / %d = %g
", num1, num2, result);
}
else
{
num2 = rand() % 10;
result = num1 * num2;
printf("%d * %d = %g
", num1, num2, result);
}
}
printf("
");
menu();
}
int operation_3()
{
printf("
");
for (i = 0; i < y; i++)
{
num1 = rand() % 100;
printf("%2d ", num1);
if (op[rand() % 4] == '/')
{
num2 = (rand() % 99) + 1;
printf("/ %2d ", num2);
}
else
{
flag = rand() % 3;
num2 = rand() % 100;
printf("%c %2d ", op[flag], num2);
}
if (op[rand() % 4] == '/')
{
num3 = (rand() % 99) + 1;
if (flag == 0)
result = num1 + (num2 * 1.0 / num3 * 1.0);
else if (flag == 1)
result = num1 - (num2 * 1.0 / num3 * 1.0);
else
result = num1 * num2 * 1.0 / num3 * 1.0;
printf("/ %2d = %g", num3, result);
}
else
{
num3 = rand() % 100;
kt = rand() % 3;
if (flag == 0 && kt == 0)
result = num1 + num2 + num3;
else if (flag == 0 && kt == 1)
result = num1 + num2 - num3;
else if (flag == 0 && kt == 2)
result = num1 + (num2 * num3);
else if (flag == 1 && kt == 0)
result = num1 - num2 + num3;
else if (flag == 1 && kt == 1)
result = num1 - num2 - num3;
else if (flag == 1 && kt == 2)
result = num1 - (num2 * num3);
else if (flag == 2 && kt == 0)
result = num1 * num2 + num3;
else if (flag == 2 && kt == 1)
result = num1 * num2 - num3;
else
result = num1 * num2 * num3;
printf("%c %2d = %g", op[kt], num3, result);
}
printf("
");
}
printf("
");
menu();
}
int main()
{
printf("==============口算生成器===============");
printf("
");
printf("欢迎使用口算生成器:");
printf("
");
help();
menu();
int x;
while (1)
{
scanf("%d", &x);
switch (x)
{
case 1:
first_grade();
break;
case 2:
second_grade();
break;
case 3:
third_grade();
break;
case 4:
help();
break;
case 5:
break;
default:
error();
}
if (x == 5)
{
break;
}
}
printf("< 执行操作:)
程序结束,欢迎下次使用
任意键结束...");
return 0;
}
2.4 gitee上传截图与链接#####
作业三四都在这个目录里面;
我的gitee