四则运算出题神器

题目:致力于解决二柱爸爸的第一个问题,出30道100以内的加减乘除给儿子做

思路:随机产生运算的两个100以内的整数x和y,m也是随机数,通过用m来控制+,-,*,/的随机出现,用for来控制循环次数30,即可实现;另外调用函数实现这些功能,便于在解决二柱爸爸今后要解决的问题,添加其他的功能实现。

主程序:

#include<iostream.h>
#include<time.h>
#include<stdlib.h>
#include<stdio.h>
void  chuti()
{  
    int x,y;
    int m;
    x=rand()%100;
    y=rand()%100;
    m=rand()%4;
    if(m==0)
      cout<<x<<'+'<<y<<'='<<endl;
    if(m==1)
      cout<<x<<'-'<<y<<'='<<endl;
    if(m==2)
      cout<<x<<'*'<<y<<'='<<endl;
    if(m==3)
      cout<<x<<'/'<<y<<'='<<endl;
}
int main()
{
    int i;
    for(i=0;i<30;i++)
        chuti();
    cout<<"Finished!Congratulations!";
    return 0;
}

 

原文地址:https://www.cnblogs.com/wantong/p/4321502.html