• C语言寒假大作战04


    这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/CST2019-4
    这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/10277
    这个作业的目标 学会如何计算出随机数四则运算的结果
    作业正文 https://i-beta.cnblogs.com/posts/edit
    其他参考文献 https://www.runoob.com/cprogramming/c-function-rand.html

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

    本次作业是在上次作业的基础上延展的,唯一差别就是有结果;
    所以只需要知道如何算得出结果就解决了作业;
    

    2.程序结果截图

    3.程序代码

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    void menu();
    void help();
    void error();
    void one();
    void two();
    void three();
    int main()
    {
    int i;
    printf("=======口算生成器======
    欢迎使用口算生成器 :)
    
    
    ");
    help();
    while(i!=5)
    {	
    	menu();
    	printf("请输入操作>");
    	scanf("%d",&i);
    	printf("<(执行操作):
    
    
    "); 
    	switch(i)
    	{
    		case 1:one();break;
    		case 2:two();break;
    		case 3:three();break;
    		case 4:help();break;
    		case 5:printf("程序结束,欢迎下次使用
    任意键结束.....
    
    
    ");break; 
    		default:error();break;
    	}		
    }
    return 0;
    } 
    void help()
    {
    printf("帮助内容:
    您需要输入命令代号来进行操作,且
    ");	
    printf("一年级题目为不超过十位数的加减法:
    ");
    printf("二年级的题目为不超过百位数的乘除法:
    ");
    printf("三年级的题目为不超过百位数的加减乘除混合题目.)
    
    
    "); 
     }
    void menu()
    {
    printf("操作列表:
    "); 
    printf("1)一年级    2)二年级    3)三年级
    ");
    printf("4)帮助      5)退出程序
    
    
    "); 
    } 
    void error()
    {
    printf("错误命令,请重新输入正确数值
    
    
    "); 
    }
    void one()
    {
    int i,n,a,b;
    double h;
    char c;
    time_t t;
    printf("现在是一年级题目:
    ");
    printf("请输入生成个数> ");
    scanf("%d",&n);
    printf("
    <执行操作 :)
    ");
    srand((unsigned) time(&t));
    for( i = 0 ; i < n ; i++ ) 
    {
    	a=rand()%10;
    	b=rand()%10;
    	if(a%2==0)
    	{
    		c='+';
    		h=a+b;
    		printf("%d %c %d = %g
    ",a,c,b,h);
    	}
    	else
    	{
    		c='-';
    		h=a-b;
    		printf("%d %c %d = %g
    ",a,c,b,h);
    	}
    }
    printf("
    
    
    ");	
    }
    void two()
    {
    int i,n,a,b;
    double h;
    char c;
    time_t t;
    printf("现在是二年级题目:
    ");
    printf("请输入生成个数> ");
    scanf("%d",&n);
    printf("
    <执行操作 :)
    ");
    srand((unsigned) time(&t));
    for( i = 0 ; i < n ; i++ ) 
    {
    	a=rand()%10;
    	b=rand()%10;
    	if(a%2==0)
    	{
    		c='*';
    		h=a*b;
    		printf("%d %c %d = %g
    ",a,c,b,h);
    	}
    	else
    	{
    		c='/';
    		h=a/b;
    		printf("%d %c %d = %g
    ",a,c,b,h);
    	}
    }
    printf("
    
    
    ");	
    }
    void three()
    {	
    int i,n=10,a,b,c,d,e;
    double h,j;
    char f,g;
    time_t t;
    printf("现在是三年级题目:
    ");
    printf("请输入生成个数> ");
    scanf("%d",&n);
    printf("
    <执行操作 :)
    ");
    srand((unsigned) time(&t));
    for( i = 0 ; i < n ; i++ ) 
    {
    	a=rand()%50;
    	b=rand()%50;
    	c=rand()%50;
    	d=rand()%4;
    	e=rand()%4; 
    	if(d==1)	
    	{
    		f='+';	
    		h=a+b;
    	}
    	if(d==2)
    	{
    		f='-';
    		h=a-b;
    	}
    	if(d==3)
    	{
    		f='*';
    		h=a*b;
    	}
    	if(d==0)
    	{
    		f='/';
    		h=a/b;	
    	}
    	if(e==0)
    	{
    		g='+';
    		j=h+c;	
    	}
    	if(e==1)	
    	{
    		g='-';
    		j=h-c;
    	}
    	if(e==2)
    	{
    		g='*';
    		j=h*c;
    	}	
    	if(e==3)	
    	{
    		g='/';
    		j=h/c;	
    	}
    	printf("%d %c %d %c %d = %g
    ",a,f,b,g,c,j);
    }
    printf("
    
    
    ");		 
    }
    

    4.Gitee上传截图和链接


    https://gitee.com/huang_yun/A04

  • 相关阅读:
    ELK04logstash 专项search
    单机Kafka集群操作
    ELK03使用kafka作为缓存收集日志
    《Vue.js 3.x高效前端开发(视频教学版)》简介
    Spring Boot上传文件功能的开发
    《Spring Boot从零开始学(视频教学版)》快速入门Spring Boot应用开发
    三本书带您快速深入掌握Spring Boot应用开发《Spring Boot从零开始学(视频教学版)》
    BamlViewer修改
    WPF Binding实现自推——强烈要求拍砖
    生活就是这么狗血——WPF粒子小记
  • 原文地址:https://www.cnblogs.com/huangyun10/p/12318940.html
Copyright © 2020-2023  润新知