随机十道四则运算
#include<stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#include <time.h>
int main()
{
int a = 0;
int b = 0;
int mode = 0;//0:
int c = 0;
int result = 0;
int score = 0;
int i = 0;
srand((unsigned)time( NULL ) );
for(i=0;i<10;i++)
{
a = rand() % 10;
b = rand() % 10;
mode = rand() % 4;
printf("%d", a);
switch(mode)
{
case 0:
printf("+ ");
result= a + b;
break;
case 1:
printf("- ");
result= a - b;
break;
case 2:
printf("* ");
result= a * b;
break;
case 3:
printf("/ ");
result= a / b;
break;
default:
printf("somethingis wrong!\n");
break;
}
printf("%d = ", b);
scanf("%d", &c);
if(c == result)
{
score+= 10;
printf("Right\n\n");
}
else
{
printf("Wrong\n\n");
}
}
printf("Yourscore is: %d\n\n\n", score);
return 1;
}
功能:随机十道四则运算
没有实现功能:不存在负数