程序源代码:

#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);
}
}

 

运行结果:

posted on 2016-03-12 16:51  cflz  阅读(252)  评论(2编辑  收藏  举报