#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char* argv[])
{
int i,j,k,y,sum;
for(int t = 0;t<30;t++)
{
i = rand()%50;
j = rand()%50;
k = rand()%4;
switch(k)
{
case 0:
sum = i+j;
printf("第%d道题:",t+1);
printf("%d+%d=%d
",i,j,sum);
break;
case 1:
if(i<j)
{
t = t-1;
break;
}
else
{
sum = i-j;
printf("第%d道题:",t+1);
printf("%d-%d=%d
",i,j,sum);
break;
}
case 2:
sum = i*j;
printf("第%d道题:",t+1);
printf("%d*%d=%d
",i,j,sum);
break;
case 3:
sum = i/j;
y = i%j;
printf("第%d道题:",t+1);
printf("%d/%d=%d...%d
",i,j,sum,y);
break;
default:
printf("出错!
");
break;
}
}
return 0;
}
这里直接将运算的答案输出在屏幕上,如果想将答案放到最后,只需建立一个整数数组sum[30],并将每道题的答案存在其中,最后输出,
这里不再一一详述。