C语言 制作一个可供小学数学运算程序

C语言 制作一个可供小学数学运算程序,第1张

先,打出c语言开始的那几行代码:

要进行两个间数字的计算首先要输入第一个数字,运算符还有第二个数字:

接着,需要对运算符进行判断,这里利用if和else if进行判断,运算结果保留两位小数:

这样就可以进行简单的两位数之间的计算了

这样程序只能执行一次,如果想让程序进行多次计算只需要嵌套一层循环即可。

将下面代码保存为test.asp,然后在可运行ASP的环境下运行即可。

示范页面:

http://www.hngczy.cn/pgb/zhidaoanswer/xiaoxuecheshiti.asp

==============test.asp==========================

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<%option explicit%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">

<title>小学数学加减乘除</title>

</head>

<body style="font-size:18pt ">

<%

if request.form("action")="ok" then

call ok()

end if

sub ok()

response.write"<font color='blue'>测试结果:(10道题,10分一题)</font><br>"

dim val(11)

dim str(11)

dim i,evl

dim zq,cw

zq=0

cw=0

for i=1 to 10

val(i)=trim(request.form("val"&i))

str(i)=request.form("str"&i)

evl=eval(str(i))

if val(i)="" or (not isnumeric(val(i))) then

response.write str(i)&"= "&val(i)&"(×)<font color='red'>请输入数字</font>。正确答案为:"&eval(str(i))&"<br>"

cw=cw+1

elseif cint(val(i))=evl then

response.write str(i)&"="&val(i)&"(√)<br>"

zq=zq+1

else

response.write str(i)&"="&val(i)&"(×)正确答案为:"&eval(str(i))&"<br>"

cw=cw+1

end if

next

response.write "<input type='button' value=' 返回重做 ' onclick='window.history.back()'> "

response.write "<input type='button' value=' 重新出题 ' onclick=""window.location.href('xiaoxuecheshiti.asp')""><br>"

response.write "正确:"&zq&"个,错误:<font color='red'>"&cw&"</font>个 ,正确率:"&round(zq/10*100,2)&"%,得分:"&zq*10&"分。<br>"

if zq/10<0.75 then

response.write "Please ask your instructor for extra help!"

elseif zq/10>0.9 then

response.write "<font color='blue'>做得不错,继续努力!</font>"

end if

response.end()

end sub

%>

<form action="xiaoxuecheshiti.asp" method="post">

<font color="blue">小学数学加、减、乘法测试题(10道题,10分一题)</font>

<br>

<%

dim a,b

dim z,i

dim temp,res

dim str(11)

i=1

randomize

do while i<11

a=int(rnd()*10)+1

b=int(rnd()*10)+1

temp=int(rnd()*3)+1

select case temp

case 1

z="+"

case 2

z="-"

case 3

z="*"

end select

str(i)=a&z&b

res=eval(str(i))

if res>0 then

response.write a&z&b&"= "&"<input name='val"&i&"' type=text'>"&"<br>"

response.write "<input name='str"&i&"' type='hidden' value="&str(i)&">"

i=i+1

end if

loop

%>

<input name="action" type="hidden" value="ok">

<input name="button" type="submit" value="我做完了,交卷">

<input name="button" type="button" value="重新出题" onclick="window.location.reload()">

</form>

</body>

</html>

=================================================

花了我一个小时,累啊!兄弟记得加分啊!:)


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

原文地址: https://outofmemory.cn/yw/11189385.html

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

发表评论

登录后才能评论

评论列表(0条)

保存