码迷,mamicode.com
首页 > 微信 > 详细

四则运算小程序

时间:2018-10-08 19:35:04      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:print   signed   windows   srand   image   rand   while   sign   float   

#include<stdio.h>
#include<Windows.h>
#include<time.h>
void main()
{
int a, b, c, d,i,m,n;
float p, q;
srand(unsigned( time(NULL)));
for (i = 1; i <=30; i++)
{
a = rand() % 100;
b = rand() % 100;
c = rand() % 5;
switch (c)
{
case 0: printf("%d + %d =\n", a, b);
break;
case 1:if (a < b)
{
d = a;
a = b;
b = d;
}
printf("%d - %d =\n", a, b);
break;
case 2:printf("%d * %d =\n", a, b);
break;
case 3:
while (b == 0)
{
b = rand() % 100;
}
printf("%d / %d =\n", a, b);
break;
case 4:
a = rand() % 100;
b = rand() % 100;
m = rand() % 100;
n = rand() % 100;
c = rand() %4 ;
while (b == 0)
{
b = rand() % 100;
}
while (n == 0)
{
n = rand() % 100;
}
if (a > b)
{
d = a;
a = b;
b = d;
}
if (m > n)
{
d = m;
m = n;
n = d;
}
switch (c)
{
case 0:printf("%d/%d + %d/%d =\n", a, b, m, n);
break;
case 1:
p = (float)a / (float)b;
q = (float)m / (float)n;
if (p < q)
{
d = a;
a = m;
m = d;
d = b;
b = n;
n = d;
}
printf("%d/%d - %d/%d =\n", a,b,m,n);
break;
case 2:printf("%d/%d * %d/%d =\n", a, b, m, n);
break;
case 3:
a = rand() % 100;
b = rand() % 100;
m = rand() % 100;
n = rand() % 100;
c = rand() % 4;
while (m == 0)
{
m = rand() % 100;
}
printf("%d/%d / %d/%d =\n", a, b, m, n);
break;
}
}
}
system("pause");
}技术分享图片

四则运算小程序

标签:print   signed   windows   srand   image   rand   while   sign   float   

原文地址:https://www.cnblogs.com/hhhh12345/p/9756170.html

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