小学二年级四则运算
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
void main()
{
int i,k,l,x,n,m,p;
char y;
srand((unsigned)time(NULL));
for (i = 0; i<30;i++)
{
k = rand() % 100;
l = rand() % 100;
x = rand() % 4;
switch (x) {
case 0:y = '+';break;
case 1:y = '-';
if (k < l) {
p = k; k = l;l = p;
}
break;
case 2:y = '*';break;
case 3:y = '/';
if (l == 0)l++;
if (l > 10) { l = l % 10; }
break;
}
printf("%d%c%d=\n", k, y, l);
}
for (i = 0; i<30;i++)
scanf_s("%d", &n);
for (i = 1; i<=30;i++)
{
k = rand() % 100;
l = rand() % 100;
x = rand() % 4;
switch (x) {
case 0:y = '+';m = k + l;break;
case 1:y = '-';if (k < l) {
p = k; k = l;l = p;
}
m = k -l;break;
case 2:y = '*';m = k * l;break;
case 3:y = '/';if (l == 0)l++;
if (l > 10) l = l % 10;
m = k / l;break;
}
printf("第%d题正确答案为%d", i, m);
}
}