编程四则运算
Posted luelue
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编程四则运算相关的知识,希望对你有一定的参考价值。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define x 6
int Test()
{
int num = 0;
int answer = 0;
int result = 0;
int a = 0;
int n = 0;
char op = 0;
int count = x;
while ( count-- )
{
a = rand() % 10;
n = rand() % 10;
op = rand() % 4;
switch ( op )
{
case 0:
op = ‘+‘;
answer = a+n;
break;
case 1:
op = ‘-‘;
answer = a-n;
break;
case 2:
op = ‘*‘;
answer = a*n;
break;
case 3:
n++;
op = ‘/‘;
answer = a/n;
break;
default:
break;
}
printf("
题目:");
printf("%d%c%d=?
", a, op, n);
printf("输入答案:");
scanf("%d", &result);
if ( answer == result )
num++;
}
return num;
}
int main()
{
srand( time(NULL) );
printf("开始答题:
");
printf("你一共答对le%d道题目。
", Test());
return 0;
}
以上是关于编程四则运算的主要内容,如果未能解决你的问题,请参考以下文章