码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算出题神器

时间:2015-03-08 12:57:52      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

题目:致力于解决二柱爸爸的第一个问题,出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;
}

 技术分享

四则运算出题神器

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!