• 第一节课堂总结


    课堂上作业是编写一个出30道100以内的四则运算,要求整数与运算符号随机产生。拿到题目首先想到要用到rand函数产生整数,在输出题目。

    程序代码:

    #include<iostream>
    using namespace std;
    void main()
    {
     int a,b,i,c;
     for(i=0;i<30;i++)
     {
      a=rand()%100+1;
         b=rand()%100+1;
      c=rand()%4+1;

      if(c==1)cout<<"("<<i+1<<")  "<<a<<"+"<<b<<"="<<endl;
      if(c==2)cout<<"("<<i+1<<")  "<<a<<"-"<<b<<"="<<endl;
      if(c==3)cout<<"("<<i+1<<")  "<<a<<"*"<<b<<"="<<endl;
      if(c==4)cout<<"("<<i+1<<")  "<<a<<"/"<<b<<"="<<endl;

     }
    }

    运行结果:

    (1)  42*68=
    (2)  1+70=
    (3)  79*59=
    (4)  65-6=
    (5)  82-28=
    (6)  92*96=
    (7)  28/37=
    (8)  5-3=
    (9)  93-83=
    (10)  17/19=
    (11)  48/27=
    (12)  39+70=
    (13)  68/100=
    (14)  95/4=
    (15)  23-34=
    (16)  65/42=
    (17)  54/69=
    (18)  45-63=
    (19)  38/60=
    (20)  42*30=
    (21)  17*36=
    (22)  43*89=
    (23)  41+43=
    (24)  49-47=
    (25)  91*30=
    (26)  51-7=
    (27)  94-49=
    (28)  24*85=
    (29)  57*41=
    (30)  77+32=
    请按任意键继续. . .

    原因:课堂上由于没有想到随机产生运算符号的方法没有成功完成要求。

  • 相关阅读:
    面向对象
    用JS添加和删除class类名
    偶然
    js-cookie的用法
    eleemnt-ui修改主题颜色
    router.go,router.push,router.replace的区别
    vue生产环境清除console.log
    特别关心
    echart
    20182330魏冰妍_预备作业
  • 原文地址:https://www.cnblogs.com/lingxi/p/4319033.html
Copyright © 2020-2023  润新知