zoukankan      html  css  js  c++  java
  • 软件工程第三次作业

    组员:李登辉。袁爱。

    #include<stdio.h>

    #include<stdlib.h>
    #include<time.h>
    int main()
    {
    int a,b,ans,res,t,i,c=0,N;
    int op;
    srand((unsigned)time(NULL));
    while(1)
    {
    printf(" ---简单四则运算练习系统--- ");
    printf("1.进行加法运算 ");
    printf("2.进行减法运算 ");
    printf("3.进行乘法运算 ");
    printf("4.进行除法运算 ");
    printf("5.退出练习 ");
    printf("请输入数字1-5: ");
    scanf("%d",&op);
    switch(op)
    {
    case 1:
    printf("--请进行加法运算-- ");
    printf("--请输入题目个数-- ");
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
    a=rand()%9+1;
    b=rand()%9+1;
    res=a+b;
    printf("%d+%d=",a,b);
    scanf("%d",&ans);
    if(ans==res)
    {
    printf("very good! ");
    c++;
    }
    else
    {
    printf("wrong answer ");
    printf("你还有一次机会 ");
    printf("%d+%d=",a,b);
    scanf("%d",&ans);
    if(ans==res)
    {
    printf("very good! ");
    c++;
    }
    else
    printf("wrong answer ");
    }
    }
    printf("***正确率为%.0f%%*** ",100.0*c/N);
    break;
    case 2:
    printf("--请进行减法运算-- ");
    printf("--请输入题目个数-- ");
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
    a=rand()%9+1;
    b=rand()%9+1;
    if(a<b)
    {t=a;a=b;b=t;}
    res=a-b;
    printf("%d-%d=",a,b);
    scanf("%d",&ans);
    if(ans==res)
    {
    printf("very good! ");
    c++;
    }
    else
    {
    printf("wrong answer");
    printf("你还有一次机会 ");
    printf("%d-%d=",a,b);
    scanf("%d",&ans);
    if(ans==res)
    {
    printf("very good! ");
    c++;
    }
    else
    printf("wrong answer ");
    }
    }
    printf("***正确率为%.0f%%*** ",100.0*c/N);
    break;
    case 3:
    printf("--请进行乘法运算-- ");
    printf("--请输入题目个数-- ");
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
    a=rand()%9+1;
    b=rand()%9+1;
    res=a*b;
    printf("%d*%d=",a,b);
    scanf("%d",&ans);
    if(ans==res)
    {
    printf("very good! ");
    c++;
    }
    else
    {
    printf("wrong answer");
    printf("你还有一次机会 ");
    printf("%d*%d=",a,b);
    scanf("%d",&ans);
    if(ans==res)
    {
    printf("very good! ");
    c++;
    }
    else
    printf("wrong answer ");
    }
    }
    printf("***正确率为%.0f%%*** ",100.0*c/N);
    break;
    case 4:
    printf("--请进行除法运算-- ");
    printf("--请输入题目个数-- ");
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
    a=rand()%9+1;
    b=rand()%9+1;
    res=a*b/b;
    printf("%d/%d=",a*b,b);
    scanf("%d",&ans);
    if(ans==res)
    {
    printf("very good! ");
    c++;
    }
    else
    {
    printf("wrong answer");
    printf("你还有一次机会 ");
    printf("%d/%d=",a,b);
    scanf("%d",&ans);
    if(ans==res)
    {
    printf("very good! ");
    c++;
    }
    else
    printf("wrong answer");
    }
    }
    printf("***正确率为%.0f%%*** ",100.0*c/N);
    break;
    case 5:goto END;
    }
    }
    END:printf("---Bye Bye--- ");
    return 0;
    }

    总结:普通的编程都不会,这些就更完全看不懂啊,请谅解!这种作业对于我们这些成绩不好的同学来说简直难如登天!

  • 相关阅读:
    python matplotlib 绘图
    python set add 导致问题 TypeError: unhashable type: 'list'
    python 子类继承父类的__init__方法
    python 内存监控模块之memory_profiler
    git log 常用命令
    wireshark使用教程
    python os.path模块
    Linux crontab 定时任务
    linux环境变量LD_LIBRARY_PATH
    Linux的ldconfig和ldd用法
  • 原文地址:https://www.cnblogs.com/rjgc123/p/4451305.html
Copyright © 2011-2022 走看看