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

    2.2.1作业头

    这个作业属于哪个课程 19级计算机1班
    这个作业要求在哪里 C语言寒假大作战04
    这个作业的目标 用程序计算口算题
    作业正文 C语言寒假大作战04
    其他参考文献 百度百科、C语言程序设计

    2.2.2 设计思路和遇到的问题

    设计思路:####只需在原来的基础上进行计算就可。

    遇到的问题:####int和double类型没有分清,导致结果的小数位很多。

    2.2.3 程序结果截图##



    2.2.4 程序代码

    include<stdio.h>

    int menu();
    int error();
    int help();
    int grade1(int a);
    int grade2(int a);
    int grade3(int a);
    int main ()
    {
    int n,m=0;
    printf("========== 口算生成器 ");
    printf("欢迎使用口算生成器 : ");
    printf(" ");
    help();
    printf(" ");
    printf(" ");
    menu();
    while(m!=1)
    {
    scanf("%d",&n);
    switch(n)
    {
    case 1:grade1(n); break;
    case 2:grade2(n); break;
    case 3:grade3(n); break;
    case 4:help(); break;
    case 5:m=1;printf("程序结束, 欢迎下次使用 任意键结束……"); break;
    default:error(); break;
    }
    }
    return 0;
    }
    int menu()
    {
    printf("操作列表: ");
    printf("1)一年级 2)二年级 3)三年级 ");
    printf("4)帮助 5)退出程序 ");
    printf("请输入操作> ");
    }
    int error()
    {
    printf("Error!!! ");
    printf("错误操作指令, 请重新输入 ");
    }
    int help()
    {
    printf("帮助信息 ");
    printf("您需要输入命令代号来进行操作, 且 ");
    printf("一年级题目为不超过十位的加减法; ");
    printf("二年级题目为不超过百位的乘除法; ");
    printf("三年级题目为不超过百位的加减乘除混合题目. ");
    }
    int grade1(int a)
    {
    int n,m,b,i,j;char op;
    printf("< 执行操作 : ");
    printf("现在是一年级的题目 ");
    printf("请输入生成个数>");
    scanf("%d",&a);
    for(i=1;i<=a;i++)
    {
    b=rand() % 2;
    if(b
    0)
    op='+';
    if(b
    1)
    op='-';
    m=rand()%10;
    n=rand()%10;
    if(op
    '-')
    j=m-n;
    if(op
    '+')
    j=m+n;
    printf("%d %c %d = %d ",m,op,n,j);
    }
    printf("执行完了 ");
    }
    int grade2(int a)
    {
    printf("< 执行操作 : ");
    printf("现在是二年级的题目 ");
    printf("请输入生成个数>");
    int n,m,b,i;char op;
    double j;
    scanf("%d",&a);
    for(i=1;i<=a;i++)
    {
    b=rand()%2;
    if(b
    0)
    op='';
    if(b1)
    op='/';
    m=rand()%10;
    n=rand()%10;
    if(n
    0&&op'/')
    n=rand()%9+1;
    if(op
    '
    ')
    j=1.0mn;
    if(op'/')
    j=1.0*m/n;
    printf("%d %c %d = %g ",m,op,n,j);
    }
    printf("执行完了 ");
    }
    int grade3(int a)
    {
    printf("< 执行操作 : ");
    printf("现在是三年级的题目 ");
    printf("请输入生成个数>");
    int n,m,b1,b2,c,i;char op1,op2;
    double sum;
    scanf("%d",&a);
    for(i=1;i<=a;i++)
    {
    b1=rand()%4;
    if(b1
    0)
    op1='';
    if(b11)
    op1='/';
    if(b1
    2)
    op1='+';
    if(b13)
    op1='-';
    m=rand()%100;
    n=rand()%100;
    if(op1
    '/'&&n0)
    n=rand()%99+1;
    b2=rand()%4;
    if(b2
    0)
    op2='
    ';
    if(b21)
    op2='/';
    if(b2
    2)
    op2='+';
    if(b23)
    op2='-';
    c=rand()%100;
    if(op2
    '/'&&c0)
    c=rand()%99+1;
    if(op1
    '+'&&op2'+')
    sum=m+n+c;
    if(op1
    '+'&&op2'-')
    sum=m+n-c;
    if(op1
    '+'&&op2'/')
    sum=m+1.0*n/c;
    if(op1
    '+'&&op2'')
    sum=m+n
    c;
    if(op1
    '-'&&op2'+')
    sum=m-n+c;
    if(op1
    '-'&&op2'-')
    sum=m-n-c;
    if(op1
    '-'&&op2'')
    sum=m-n
    c;
    if(op1
    '-'&&op2'/')
    sum=m-1.0*n/c;
    if(op1
    ''&&op2=='-')
    sum=1.0
    mn-c;
    if(op1=='
    '&&op2'+')
    sum=1.0mn+c;
    if(op1
    ''&&op2=='')
    sum=mnc;
    if(op1'*'&&op2'/')
    sum=1.0mn/c;
    if(op1'/'&&op2'-')
    sum=1.0m/n-c;
    if(op1'/'&&op2'+')
    sum=1.0
    m/n+c;
    if(op1'/'&&op2'')
    sum=1.0
    m/nc;
    if(op1'/'&&op2'/')
    sum=1.0
    m/n/c;
    printf("%d %c %d %c %d = %g ",m,op1,n,op2,c,sum);
    }
    printf("执行完了 ");
    }

    2.2.5 Gitee上传截图与链接



    我的仓库

  • 相关阅读:
    解决百度云大文件不能被其他下载器下载
    python中IndentationError: expected an indented block错误的解决方法
    2017Windows下安装pip
    α-β剪枝算法的java语言实现(非常实用)
    flask+sqlite3+echarts2+ajax数据可视化
    flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: 'utf8' codec can't decode byte解决方法
    Windows下快速安装Flask的一次经历
    决策树ID3算法的java实现(基本适用所有的ID3)
    继续上篇抢QQ口令红包,抢那招抢不了的红包技巧
    【QQ红包】手机发抢不到的口令红包
  • 原文地址:https://www.cnblogs.com/zengzi123/p/12323256.html
Copyright © 2011-2022 走看看