C语言编写一个算术运算测试程序。要求完成10以内的加减运算。这个程序求它的解释。希望各路高手帮帮忙注释

C语言编写一个算术运算测试程序。要求完成10以内的加减运算。这个程序求它的解释。希望各路高手帮帮忙注释,第1张

#include "stdio.h"

#include "stdlib.h"

#include "time.h"

int main()

{

int n,f

int a,b,c,t

int s=1

while(s==1)

{

t=1,f=0

/**提示用户输入*/

printf("欢迎进入小学算数测试系统。。请输入你要挑战的题量:")

scanf("%d",&n)

int q=n

/**以时间做种子*/

srand((unsigned)time(NULL))

//题数都问了就结束

while(n!=0)

{

printf("问题%d:\n",t)

t++

/**产生两个0到9的随机数*/

a=rand()%10

b=rand()%10

/**一秒回答一个问题*/

if((unsigned)time(NULL)%2==0)

{

printf("%d+%d=?\n",a,b)

printf("请答题:")

scanf("%d",&c)

if(c==a+b)

/**如果答案对了 答对数量加一题*/

f++

else

{

/**答错就输出正确答案*/

printf("\a")

printf("答案错误,正确结果为:%d\n",a+b)

}

/**题数减少一道*/

n--

}

/**下同if()的*/

else

{

printf("%d-%d=?\n",a,b)

printf("请答题:")

scanf("%d",&c)

if(c==a-b)

f++

else

{

printf("\a")

printf("答案错误,正确结果为:%d\n",a-b)

}

n--

}

}

/**输出这次考试的各组数据*/

printf("考试结果:\n")

printf("算对%d道题,",f)

printf("算错%d道题,",q-f)

printf("分数为:%d分\n",f)

printf("退出请输入0,继续请输入1\n")

scanf("%d",&s)

}

return 0

}

望采纳

能根据输入题数出题 什么意思

有个题库?

界面要求:美观简洁 什么标准

作者满意就可?

实现起来应该不难

晚上9点以后我可以帮你做

好办 我帮你写吧 能否多给点分呢 (*^__^*) 嘻嘻……

晚上10点前给你答案

花了一个中午给你编的,还增加了计算分数功能

界面没有做 需要的话再联系

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int Getanum(int num)

{

int a

srand(num*num+time(0))

a=(rand()+num)%10//产生10以内的随机数

return a

}

void main()

{

int i,num,a,b,c,op,error

error = 0//错误数置零

num = 100//使得下面的while循环成立即可

while(!(num>0&&num<10))//只接受10以内的题目数

{

printf("Please input the sum of exam :")

scanf("%d",&num)

}

for(i=0i<numi++)//每次出题开始

{

a = Getanum(i)//第一个 *** 作数

b = Getanum(a)//第二个

op = (Getanum(a+b)+b)/a%2//产生符号 +或者-

switch(op)

{

case 0://+

if(a+b>10)//超过10重新来

{

i--

break

}

else

{

printf("%d : %d + %d = ",i+1,a,b)//出题

scanf("%d",&c)//取输入的结果

if(c != a+b)//答案错误

{

printf("Error!\n")

error++

}

else//正确答案鼓励一下

{

printf("Good!\n")

}

}

break

case 1://-

if(b>a)//保证a>b 使得不出现负数

{

a=a+b

b=a-b

a=a-b

}

printf("%d : %d - %d = ",i+1,a,b)//出题

scanf("%d",&c)//取结果

if(c != a-b)

{

printf("Error!\n")

error++//错误自加

}

else

{

printf("Good!\n")

}

break

default:

break

}

}

printf("%d errors!\n",error)//输出错误数

printf("Your mark is %d .\n",(num-error)*100/num)//所得分数

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12105080.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-21
下一篇2023-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存