zoukankan      html  css  js  c++  java
  • 随机生成30道小学二年级四则远算题目

    一家软件公司程序员二柱的小孩上了小学二年级,老师让家长每天出30道四则运算题目给小学生做。

    二柱子立马就想到写一个小程序来做这件事。这个事情可以用很多语言或者工具来实现:Excel,C/C++,C#,VB,Unix Shell,Emacs,Powershell/Vbscropt,Javascript,Perl,Python,...

    我选择的是C++,软件为VS 

    源代码为:

     1 #include <iostream>
     2 #include <time.h>
     3 #include <string>
     4 using namespace std;
     5 
     6 void main()
     7 {
     8 int A[30],B[30],i,k;
     9 string C;                                         //因为除号想用“÷”,所以要用“string”类
    10 srand((unsigned)time(NULL));      //这里没有设定随机种子,则使用系统定时/计数器的值做为随机种子
    11                                                      //所以,在相同的平台环境下,编译生成exe后,每次运行它,显示的随机数会是伪随机数,即每次运行显示的结果会有不同。 
    12 for(i = 0;i<30;i++)
    13 {
    14 k = rand()%4;                               //产生随机符号
    15 if(k == 0)
    16 C = "+";
    17 else if(k == 1)
    18 C = "-";
    19 else if(k == 2)
    20 C = "*";
    21 else if(k == 3)
    22 C = "÷";
    23 A[i] = rand()%100;
    24 B[i] = rand()%100;
    25 if(C == "+")                                  //输出题目
    26 {cout<<A[i]<<"+"<<B[i]<<"="<<endl;}
    27 else if(C == "-")
    28 {cout<<A[i]<<"-"<<B[i]<<"="<<endl;}
    29 else if(C =="*")
    30 {cout<<A[i]<<"*"<<B[i]<<"="<<endl;}
    31 else if(C == "÷")
    32 {cout<<A[i]<<"÷"<<B[i]<<"="<<endl;}
    33 }
    34 }

    结果截图:

  • 相关阅读:
    Intersection
    B-number
    Intersecting Lines
    Segments
    G. Swapping Places
    Toy Storage
    TOYS
    哈密顿绕行世界问题
    java试题复盘——11月25日
    java试题复盘——11月13日
  • 原文地址:https://www.cnblogs.com/shenzhenxi/p/9756506.html
Copyright © 2011-2022 走看看