首页 > 其他 > 详细

四则运算1

时间:2015-07-02 21:02:02      阅读:153      评论:0      收藏:0      [点我收藏+]

20分钟内写一个100以内的随机四则用算

C++程序源代码:

#include<iostream>

#include<ctime>

using namespace std;

int main()

{  

int i,j,k;  

srand((unsigned) time(NULL));

 for(int a=0 ;a<30;a++)  

{  

 i=rand()%100;   

j=rand()%100;   

k=rand()%4;

  if (k==1)    

cout<<i<<"+"<<j<<"="<<endl;   

if (k==2)    

cout<<i<<"-"<<j<<"="<<endl;   

if (k==3)    

cout<<i<<"*"<<j<<"="<<endl;   

if (k==0)    

cout<<i<<"/"<<j<<"="<<endl;    

}  

return 0;

}

20分钟内没有完成是因为rand()函数不熟练,练习不多。

四则运算1

原文:http://www.cnblogs.com/helloalbert/p/4617099.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!