/应王老师要求,需要编写一个能够“得出三十道两位数的四则运算,不能重复” 的程序,设计如下。
预估时间:5 h
实际时间:三天,每天2h
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define RANDOM(a,b) (rand()%((b+1)-(a)) + (a))
#define GEN_VALUE() RANDOM(1, 100)
#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[] = { '+', '-', '*', '/' };
{
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) ];
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= ", x,cs,y );
a++;
}
}
}
调试完成

吴强