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

    问题 回答
    这个作业属于哪个课程 班级链接
    这个作业要求在哪里 作业要求链接
    这个作业的目标 编写各年级题目操作函数,学习rand随机函数
    作业正文 正文链接
    其他参考文献 《C Prime Plus》《随机数rand资料》《CSDN》

    1. 设计思路和遇到的问题

    1.1 设计思路

    • 菜单程序函数调用图:

    • 思路:自定义函数一年级的题目的程序,用rand随机数来表示题目要求的数和标点符号,标点符号定义字符型变量,和上次作业差不多的格式。

    1.2 遇到的问题

    • 对rand的理解不是很明白,除了看作业资料中rand的用法,我不能明白的其实是rand()%后面的字母的意思,然后百度搜索了下。

    2. 程序结果截图

    3. 程序代码

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

    4. Gitee上传截图与链接

    4.1 截图

    4.2 链接

    20199250

  • 相关阅读:
    Python中的BeautifulSoup模块
    requests模块
    requests模块
    python中让输出不换行
    python中让输出不换行
    我为Dexposed续一秒——论ART上运行时 Method AOP实现
    Python2中的urllib、urllib2和 Python3中的urllib、requests
    Python2中的urllib、urllib2和 Python3中的urllib、requests
    Fidder抓包软件的使用
    Fidder抓包软件的使用
  • 原文地址:https://www.cnblogs.com/1076022899-lj/p/12295635.html
Copyright © 2011-2022 走看看