二柱子四則運算簡單
阿新 • • 發佈:2018-10-06
() ret rand lib case printf 技術分享 image main
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int x,y,z,t;
srand(time(NULL));
printf("二柱子的計算題:\n");
for(int i=0;i<30;i++)
{
x=rand()%100;
y=rand()%100;
z=rand()%4;
switch(z)
{
case 0:
printf("%d+%d=\n",x,y);
break;
case 1:
if(x<y)
{
t=x;
x=y;
y=t;
}
printf("%d-%d=\n",x,y);
break;
case 2:
printf("%d×%d=\n",x,y);
break;
case 3:
if(y!=0)
{
printf("%d÷%d=\n",x,y);
}
else
{
i=i-1;
}
break;
default:
printf("超出測試範圍\n");
break;
}
}
printf("endl.\n");
return 0;
}
二柱子四則運算簡單