二年级的30道四则运算题

想法思路:(1)在1-100之内产生两个随机数,并且随机的进行四则运算;

              (2)循环进行30次,产生30道题;

              (3)二年级时,没有学到分数和负数,减数要小于或等于被减数。

源程序代码:

#include "stdafx.h"

#include"iostream.h"

#include"stdlib.h"

#include"math.h"
#include"time.h"

int main(int argc, char* argv[])

{    

        int a,b;    

        int m;   

        srand( (unsigned)time( NULL ) );

        for(int i=1;i<=30;i++)  

       {   

                a=rand()%100;     

                b=rand()%100;  

                m=rand()%4;   

                switch(m)   

               {    

                      case 0:     

                           cout<<i<<" "<<a<<"+"<<b<<"="<<endl;    

                           break;    

                      case 1:    

                            if(a>=b)    

                            {     

                                  cout<<i<<" "<<a<<"-"<<b<<"="<<endl;     

                                  break;    

                             }   

                      case 2:    

                              cout<<i<<" "<<a<<"x"<<b<<"="<<endl;    

                              break;   

                      case 3:    

                                     cout<<i<<" "<<a<<"/"<<b<<"="<<endl;    

                                     break;   

                  }  

            }

             return 0;

}

 结果截图如下:

posted @ 2015-03-06 13:30  快乐宝贝hyp  阅读(319)  评论(0编辑  收藏  举报