C语言寒假大作战03

醉酒当歌 提交于 2020-02-12 17:35:19

2.2.1

这个作业属于哪个课程 [班级链接](https://edu.cnblogs.com/campus/zswxy/CST2019-2
这个作业要求在哪 https://edu.cnblogs.com/campus/zswxy/CST2019-2/homework/10271
作业正文 https://i-beta.cnblogs.com/posts/edit
这个作业的目标 编写各年级题目操作函数,学习rand随机函数
其他文献 《C Prime Plus》《随机数rand资料》

2.2.2 设计思路和遇到的问题

对于rand随机函数理解不清楚

2.2.3 程序结果截图



2.2.4 程序代码

#include<stdio.h>
#include<stdlib.h>
void operation1(){
    int a,b,i;
    printf("现在是一年级题目:\n请输入生成个数>");
    scanf("%d",&a);
    for(i=0;i<a;i++){
        int shu1=rand()%12;
        int shu2=rand()%12;
        char fh[2]={'+','-'};
        b=rand()%2;
        printf("%2d %c %2d=___\n",shu1,fh[b],shu2);
    }
} 
void operation2(){
    int a,b,i;
    printf("现在是二年级题目:\n请输入生成个数>");
    scanf("%d",&a);
    for(i=0;i<a;i++){
        int shu1=rand()%102;
        int shu2=rand()%102;
        int shu3=rand()%100+6;
        char fh[2]={'*','/'};
        b=rand()%2;
        if(fh[b]=='/')printf("%2d %c %2d=___\n",shu1,fh[b],shu3);
        else printf("%2d %c %2d=___\n",shu1,fh[b],shu2);
    }
}
void operation3(){
    int a,b,i,b1;
    printf("现在是三年级题目:\n请输入生成个数>");
    scanf("%d",&a);
    for(i=0;i<a;i++){
        int shu1=rand()%104;
        int shu2=rand()%104;
        int shu3=rand()%104;
        int shu4=rand()%100+6;
        char fh[4]={'+','-','*','/'};
        b=rand()%4;
        b1=rand()%4;
        if(fh[b]=='/'&&shu2==0) shu2=shu4;
        if(fh[b1]=='/'&&shu3==0) shu3=shu4;
        printf("%2d %c %2d %c %2d=___\n",shu1,fh[b],shu2,fh[b1],shu3);
        
    }
}
void menu(){
    printf("操作列表:\n1)一年级    2)二年级    3)三年级\n4)帮助     5)退出程序\n请输入操作>");
} 
void help(){
    printf("帮助信息:\n您需要输入命令代号来进行操作,且\n一年级题目为不超过十位的加减法;\n二年级题目为不超过百位的乘除法;\n三年级题目为不超过百位的加减乘除混合题目.\n\n");
} 
void error(){
    printf("Error!!!\n错误操作指令,请重新输入\n\n"); 
}
int main(){
    int Grade=1;
    printf("========口算生成器========\n欢迎使用口算生成器:)\n\n");
    help();
    menu();
    while(Grade!=5){
        scanf("%d",&Grade);
        printf("<执行操作:)\n\n");
        switch(Grade){
            case 1:operation1();break;
            case 2:operation2();break;
            case 3:operation3();break;
            case 4:help();break;
            case 5:printf("程序结束,欢迎下次使用  任意键结束......\n");break;
            default:error();break;
        }if(Grade!=5) menu();
    }
    return 0;
}

2.2.5 Gitee上传截图与链接


链接

https://gitee.com/gaozp123456/dashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!