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
    这个作业的目标是 熟悉用函数和switch语句编程口算题菜单,还有随机数rand的使用
    作业正文 随机数的使用
    参考文献 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();
    void operation_2();void two();
    void operation_3();void three();
    
    int main()
    {
        int m;
        printf("========== 口算生成器 ==========
    欢迎使用口算生成器 :
    希望早日开学
    ");
        printf("
    ");
        help();
        while(1)
        {
            menu();
            scanf("%d",&m);
            switch(m)
            {
                case 1:operation_1();break;
                case 2:operation_2();break;
                case 3:operation_3();break;
                case 4:help();break;
            }
            printf("
    ");
            if(m==5) break;
            if(m>5||m<1) error();
        }
        return 0;
    }
    void help()
    {
        printf("帮助信息
    您需要输入命令代号来进行操作, 且
    ");
        printf("一年级题目为不超过十位的加减法;
    二年级题目为不超过百位的乘除法;
    ""三年级题目为不超过百位的加减乘除混合题目.
    ");
        printf("
    ");
    }
    void menu()
    {
        printf("操作列表:
    1)一年级    2)二年级    3)三年级
    4)帮助      5)退出程序
    请输入代号:");
    }
    void error()
    {
        printf("错误程序,请重新输入正确数值。");
        printf("
    ");
     } 
     void operation_1()
     {
        printf("请输入题目个数>");
        one();
     }
      void operation_2()
     {
        printf("请输入题目个数>");
        two();
     }
      void operation_3()
     {
        printf("请输入题目个数>");
        three();
     }
      void one()
     {
        int x,a,b,c;
        scanf("%d",&x);
        printf("现在是一年级题目:
    "); 
        srand((unsigned)time(NULL));
        for(int i=1;i<=x;i++)
        {
            a=rand()%10;
            b=rand()%10;
            c=rand()%2;
            switch(c){
            	case 0:printf("%d + %d = ___",a,b);break;
            	default: printf("%d - %d = ___",a,b);
    		}
    		printf("
    ");
         } 
     } 
     void two()
     {
        int x,a,b,c;
        scanf("%d",&x);
        printf("现在是二年级题目:
    "); 
        srand((unsigned)time(NULL));
        for(int i=1;i<=x;i++)
        {
            a=rand()%100;
            b=rand()%100;
            c=rand()%4;
            if(c==0)
            printf("%3d * %3d = ___",a,b);
            else
            printf("%3d / %3d = ___",a,b);
            printf("
    ");
         } 
     }
     void three()
     {
        int x,a,b,c;
        scanf("%d",&x); 
        printf("现在是三年级题目:
    "); 
        srand((unsigned)time(NULL));
        for(int i=1;i<=x;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/deng_zhi_zhu/dashboard

  • 相关阅读:
    js 右击
    javascript 中的函数,控制流, 事件委托
    javascript 的 this , js 线程
    javascript 中的var : 隐含变量 全局变量 变量提升
    明日
    ajax循环json 中的 for(var prop in data) 与 hasProperty()
    js继承机制
    callee, caller,toString(),String()
    解决eclipse中jsp下无代码提示问题
    商业模式
  • 原文地址:https://www.cnblogs.com/dengzhizhuo/p/12272640.html
Copyright © 2011-2022 走看看