二年级四则运算三十道

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define RANDOM(a,b) (rand()%((b+1)-(a)) + (a))
#define GEN_VALUE() RANDOM(1, 100)

void main()
{
int x, y, t, r, a=0;
char cs, csn[] = { '+', '-', '*', '/' };

srand( (unsigned)time(NULL) );
while(a<30)
{
x = GEN_VALUE();
y = GEN_VALUE();
cs = csn[ RANDOM(0,3) ];


if( x<y )
{
t = x;
x= y;
y = t;
}


if( cs=='/' && x%y!=0 )
continue;


switch(cs)
{
case '+': (float)x+(float)y; break;
case '-': (float)x-(float)y; break;
case '*': (float)x*(float)y; break;
case '/': (float)x/(float)y; break;
}


printf( "%d%c%d=\n", x,cs,y );
a++;

}
}

猜你喜欢

转载自www.cnblogs.com/tu1603liwen/p/9750236.html
今日推荐