小学生整数四则运算
2016-03-12 16:51
239 查看
程序源代码:
#include <stdio.h>
#include <stdlib.h>
void main()
{
int n,a,b,i;
int answer;
for (i=0;i<100;i++)
{ a=rand()%100;
b=rand()%100;
n=rand()%4;
switch(n)
{case 0:printf("%d+%d=",a,b);
answer=a+b;
break;
case 1:
while(a-b<0)
{a=rand()%100;
b=rand()%100;
}
printf("%d-%d=",a,b);
answer=a-b;
break;
case 2:printf("%d*%d=",a,b);
answer=a*b;
break;
case 3:
while(a%b!=0)
{a=rand()%100;
b=rand()%100;}
printf("%d/%d=",a,b);
answer=a/b;
break;
}
printf("\t\t\t\t\t\t\t\t\%d\n",answer);
}
}
运行结果:
#include <stdio.h>
#include <stdlib.h>
void main()
{
int n,a,b,i;
int answer;
for (i=0;i<100;i++)
{ a=rand()%100;
b=rand()%100;
n=rand()%4;
switch(n)
{case 0:printf("%d+%d=",a,b);
answer=a+b;
break;
case 1:
while(a-b<0)
{a=rand()%100;
b=rand()%100;
}
printf("%d-%d=",a,b);
answer=a-b;
break;
case 2:printf("%d*%d=",a,b);
answer=a*b;
break;
case 3:
while(a%b!=0)
{a=rand()%100;
b=rand()%100;}
printf("%d/%d=",a,b);
answer=a/b;
break;
}
printf("\t\t\t\t\t\t\t\t\%d\n",answer);
}
}
运行结果:
相关文章推荐
- yii2 表单提交一直报错 或者页面脚本写ajax,用firbug调试总是找不到地址页面404
- 软件工程--复利计算1.0,2.0---代码及运行结果截图
- spring error
- lsof
- C# 输入一个年份判断是不是闰年
- CodeForces 622A:Infinite Sequence【排列】
- JAVA多线程和并发基础
- EventBus3.0使用详解
- Wifi启动流程分析
- 作业二:附录流行的源程序版本管理软件和项目管理软件都有哪些?
- poj 2739 Sum of Consecutive Prime Numbers 水题 筛法
- AlphaGo三比零完胜李世石
- AlphaGo三比零完胜李世石
- 转载一个MFC下好用的高速绘图控件-(Hight-Speed Charting)以备后用
- mysql数据库连接池使用(一)dbcp方式的配置
- linux 复习杂记(一) linux中的进程
- mysql数据库连接池使用(一)dbcp方式的配置
- android strings.xml的特殊字符
- 20160312中艺收盘分析
- NIO学习系列:核心概念及基本读写