zoukankan      html  css  js  c++  java
  • C语言寒假大作战03

    问题 答案
    这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/10269
    这个作业要求在哪 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/10269
    这个作业的目标 运用rand()函数
    作业正文 https://i.cnblogs.com/posts/edit;postId=12297716
    其他参考文献 百度 csdn https://www.runoob.com/cprogramming/c-function-rand.html

    2.2.2设计思路和遇到的问题

    设计思路:

    在上次作业的基础上运用rand函数。

    2.2.3 程序结果截图



    2.2.4 程序代码

    #include <stdio.h>
    #include<stdlib.h>
    #include<time.h> 
    void menu();
    void help();
    void error();
    void operation_1();
    void one_1();
    void operation_2();
    void two_1();
    void operation_3();
    void three_1();
    int main()
    {
    	int n;
    	printf("========== 口算生成器 ==========
    ");
    	printf("欢迎使用口算生成器 :
    ");
    	printf("小学生必备神器
    ");
    	printf("
    ");
    	help();
    	while (1)
    	{
    		menu();
    		scanf_s("%d", &n);
    		switch (n)
    		{
    		case 1:operation_1(); break;
    		case 2:operation_2(); break;
    		case 3:operation_3(); break;
    		case 4:help(); break;
    		}
    		printf("
    ");
    		if (n == 5) break;
    		if (n > 5 || n < 1) error();
    	}
    	return 0;
    }
    void help()
    {
    	printf("帮助信息
    ");
    	printf("您需要输入命令代号来进行操作
    ");
    	printf("一年级题目为不超过十位的加减法
    ");
    	printf("二年级题目为不超过百位的乘除法
    ");
    	printf("三年级题目为不超过百位的加减乘除混合题目
    ");
    	printf("
    ");
    }
    void menu()
    {
    	printf("操作列表:
    1)一年级    2)二年级    3)三年级
    ");
    	printf("4)帮助      5)退出程序
    请输入代号:");
    }
    void error()
    {
    	printf("哦买噶 错啦 请重新输入 ");
    	printf("
    ");
    	printf("
    ");
    }
    void operation_1()
    {
    	printf("请输入题目数量>");
    	one_1();
    }
    void operation_2()
    {
    	printf("请输入题目数量>");
    	two_1();
    }
    void operation_3()
    {
    	printf("请输入题目数量>");
    	three_1();
    }
    void one_1()
    {
    	int n, a, b, c;
    	scanf_s("%d", &n);
    	printf("一年级题目如下:
    ");
    	srand((unsigned)time(NULL));
    	for (int i = 1; i <= n; i++)
    	{
    		a = rand() % 10 + 1;
    		b = rand() % 10 + 1;
    		c = rand() % 2;
    		if (c == 0)
    			printf("%2d + %2d = ___", a, b);
    		else
    			printf("%2d - %2d = ___", a, b);
    		printf("
    ");
    	}
    }
    void two_1()
    {
    	int n, a, b, c;
    	scanf_s("%d", &n);
    	printf("二年级题目如下:
    ");
    	srand((unsigned)time(NULL));
    	for (int i = 1; i <= n; i++)
    	{
    		a = rand() % 100;
    		b = rand() % 100;
    		c = rand() % 2;
    		if (c == 0)
    			printf("%3d * %3d = ___", a, b);
    		else
    			printf("%3d / %3d = ___", a, b);
    		printf("
    ");
    	}
    }
    void three_1()
    {
    	int n, a, b, c;
    	scanf_s("%d", &n);
    	printf("三年级题目如下:
    ");
    	srand((unsigned)time(NULL));
    	for (int i = 1; i <= n; i++)
    	{
    		a = rand() % 100;
    		b = rand() % 100;
    		c = rand() % 4;
    		switch (c)
    		{
    		case 0:printf("%3d + %3d = ___", a, b); break;
    		case 1:printf("%3d - %3d = ___", a, b); break;
    		case 2:printf("%3d * %3d = ___", a, b); break;
    		case 3:printf("%3d / %3d = ___", a, b); break;
    		}
    		printf("
    ");
    	}
    }
    

    2.2.5Gitee上传截图与链接

    https://gitee.com/xiaodanfeng

  • 相关阅读:
    项目
    Cache Code
    是什么限制了我们面向对象
    程序设计语言本质
    不要迷失在技术的海洋中
    程序是给自己看的还是给别人看的
    程序员的春天
    新手如何学习一门新的语言
    无废话C#设计模式之二十:Mediator
    (原创)代码分析-DataGrid实现增删(带提示)改和分页
  • 原文地址:https://www.cnblogs.com/xdf-123/p/12297716.html
Copyright © 2011-2022 走看看