怎样用c语言编写个能随机出10以
#include "stdio。h"
#include "stdlib。h"
#include "time。h"
#include "string。h"
void main()
{
int firstNum, secondNum, operatorNum, result, intInput;
char operatorChar;
char inputTemp[256];
srand(time(NULL));
while (1)
{
firstNum = rand() % 10;
secondNum = rand() % 10;
operatorNum = rand() % 2;
if (o...全部
#include "stdio。h"
#include "stdlib。h"
#include "time。h"
#include "string。h"
void main()
{
int firstNum, secondNum, operatorNum, result, intInput;
char operatorChar;
char inputTemp[256];
srand(time(NULL));
while (1)
{
firstNum = rand() % 10;
secondNum = rand() % 10;
operatorNum = rand() % 2;
if (operatorNum == 0)
{
operatorChar = '+';
result = firstNum + secondNum;
}
else
{
operatorChar = '-';
result = firstNum - secondNum;
}
printf("input 'q' to exit\n\n");
printf("\nlet's go。
。。\n");
printf("\t\t%d %c %d = ", firstNum, operatorChar, secondNum);
scanf("%s", inputTemp);
if (inputTemp[0] == 'q')
break;
intInput = atoi(inputTemp); /*转换不成功则intInput==0,而正确输入也可以为0,这里没有处理!*/
if (intInput == result)
{
printf("\tright next。
。。");
sleep(1);
clrscr();
continue;
}
else
{
printf("\terror next。
。。
");
sleep(1);
clrscr();
continue;
}
}
}
。收起