#include <stdlib.h>
#include <time.h>
const int MAXSIZE = 10
int CheckResult(int anwser,int result) {
if(anwser == result) {
printf("对的,继续努力\n")
return 1
}
printf("错了,正确答案是:%d\n",result)
return 0
}
int main() {
int a,b,t,answer,result
int n = MAXSIZE,yes = 0,no = 0
char op,ops[] = {"+-*/"}
srand((unsigned)time(NULL))
while(n--) {
op = rand()%4
switch(ops[op]) {
case 行烂'+' : do {
a = rand()%90 + 10
b = rand()%90 + 10
}while(a + b >= 100)
printf("%d + %d = ",a,b)
scanf("%d",&answer)
if(CheckResult(answer,a + b)) ++yes
else ++no
break
case '-' : a = rand()%90 + 10
b = rand()%90 + 10
if(a < b) {t = a a = b b = t }
printf("%d - %d = ",a,b)
scanf("%d",&answer)
if(CheckResult(answer,a - b)) ++yes
else ++no
break
case '*' : do {
a = rand()%100
b = rand()%100
}while(a * b >= 100)
printf("%d * %d 枣郑= ",a,b)
scanf("%d",&answer)
if(CheckResult(answer,a * b)) ++yes
else ++no
break
case '/' : 档岩漏do {
a = rand()%90 + 1
b = rand()%90 + 1
}while(a % b && b % a)
if(a % b) {t = a a = b b = t }
printf("%d / %d = ",a,b)
scanf("%d",&answer)
if(CheckResult(answer,a / b)) ++yes
else ++no
break
}
}
printf("答对:%d个,答错:%d个,正确率:%.2lf%%\n",yes,no,100.0 * yes / MAXSIZE)
return 0
}
#include<stdio.h>#include<time.h>
#include<stdlib.h>
#include<math.h>
int i=0,s=0,a,b,f=0,c,stdans,userans,boolean
/*i控制当前题号,s是分数,
a,b是当前参与运算的数字,
f是一道题中已经用掉的机会,
c是运算符号,stdans是标准答案,
userans是用户答案,
boolean保存该题是否已经答对
*/
int array[3]={10,7,5}//保存3个每道题可能累加上的分数(非0)
int main()
{
srand(time(0))//初始化随机数发生器
while(i<10){
a=rand()%51//产生随机数a(0<=a<=50)
b=rand()%51//产生随机数b(0<=b<=50)
if(a+b>50 || a-b<0)continue//保证题没笑目不超出低年级水平所及范围
c=rand()%2
if(c==0){printf("%d、%d+%d=",i+1,a,b)stdans=a+b}
else {printf("%d、%d-%d=",i+1,a,b)stdans=a-b}
//决定运算符并输出题号及算式
while(f<=2){
scanf("%d",&userans)//输入答案
if(f==2)break
if(userans==stdans){//若答案正确
printf("正确!\n")
boolean=1
s+=array[f]
break//则输出信息、更改变量状态、累加分数、结束循环
}//当机会没用完时继续循环
else{
printf("错误!你还有%d次机会:",2-f)
f++
boolean=0
}//否则再来
}
if(boolean==0)printf("你没有机会了!正确答案是:%d\n",stdans)//三次没答对时
f=0//初始化f
i++//题号增加
}
printf("答题结束!你的成绩是:")
if(s>烂樱=90)printf("SMART\n")
else if(s>=80)printf("饥察丛GOOD\n")
else if(s>=70)printf("OK\n")
else if(s>=60)printf("PASS\n")
else printf("TRY AGAIN\n")//输出成绩
system("pause")//可删,只是相当于cmd.exe(系统自带命令解释程序)中的pause命令
return 0
}
//我是用C++编译但刻意以C语言形式写的,可能有些小小的不兼容。如果有就找我。
完美!请看我的作品:#include
<stdio.h>
#include
<time.h>
#include
<stdlib.h>
#include
<conio.h>
#define
N
10
typedef
struct
_ti
{
int
a,
b
int
op
int
result
int
input
int
rw
}ti
ti
timu[N]
int
fen
int
flag
int
mulu()
{
int
s
while(1)
{
printf("\t\t欢迎进入super考试系统\n\n")
printf("1)随机出题\t\t\t\t")
printf("2)开始考试\n")
printf("3)试卷评分\t\t\t\t")
printf("4)显示批改的试卷\n")
printf("5)退出系统\n\n")
printf("请做出选择:")
scanf("%d",
&s)
while(getchar()
!=
'\n')
if(s
<
1
||
s
>
5)
printf("选择有误!请重新输入.\n")
else
break
}
return
s
}
void
chuti()
{
int
i,
f
printf("确认随机出%d道题吗?(y确认):",
N)
if(getchar()
!=
'y')
return
for(i
=
0,
f
=
1
i
<
N
f
?
i++
:
0)
{
timu[i].a
=
rand()
%
100+1
timu[i].b
=
rand()
%
100+1
timu[i].op
=
rand()
%
4
if(timu[i].b
==
0
&&
timu[i].op
==
3)
{
f
=
0
continue
}
else
f
=
1
switch(timu[i].op)
{
case
0:
timu[i].result
=
timu[i].a
+
timu[i].bbreak
case
1:
timu[i].result
=
timu[i].a
-
timu[i].bbreak
case
2:
timu[i].result
=
timu[i].a
*
timu[i].bbreak
case
3:
timu[i].result
=
timu[i].a
/
timu[i].bbreak
}
}
printf("出题完毕!\n")
flag
=
1
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)