<iostream>
#include
<ctime>
using
namespace
std
int
main()
{
int
a,b
int
num
int
t=10,d=100
srand((unsigned)time(0))
a=rand()%(d-t)+t
printf("当前随机数为:%d\n",a)
printf("请输入一个数:
")
scanf("%d",&num)
if(a==num)
printf("正确!\n")
else
while(true){
a=rand()%(d-t)+t
b=rand()%(d-t)+t
printf("当前随机数为:%d\n",a+b)
printf("请输入一个数:
")
scanf("%d",&num)
if(num==(a+b)){
printf("正确\n")
break
}
}
return
0
}
#include <iostream>#include <ctime>
using namespace std
int main()
{
int a,b
int num
int t=10,d=100
srand((unsigned)time(0))
a=rand()%(d-t)+t
printf("当前随机数为:%d\n",a)
printf("请输入一个数: ")
scanf("%d",&num)
if(a==num)
printf("正确!\n")
else
while(true){
a=rand()%(d-t)+t
b=rand()%(d-t)+t
printf("当前随机数为:%d\n",a+b)
printf("请输入一个数: ")
scanf("%d",&num)
if(num==(a+b)){
printf("正确\n")
break
}
}
return 0
}
import java.util.*public class P
{
public static void main(String[] args)
{
final int ScorePerExam=10
Scanner sc=new Scanner(System.in)
Random r=new Random(Calendar.getInstance()
.getTimeInMillis())
int n=0,right=0,wrong=0,num,sum,answer
boolean exit=false,jixu
String menu
while(!exit)
{
System.out.println("Y、开始测试")
System.out.println("Q、退出系统")
System.out.print("请选择一个菜单:")
menu=sc.nextLine().substring(0,1).toUpperCase()
switch(menu)
{
case "Y":
jixu=true
n=right=wrong=0
while(jixu &&n<10)
{
sum=r.nextInt(101)
num=r.nextInt(101)
System.out.printf("%d+%d=",sum,num)
sum+=num
try
{
answer=Integer.parseInt(sc.nextLine())
if(sum==answer)
{
System.out.println("Correct")
right++
}
else
{
System.out.println("Error")
wrong++
}
}
catch(Exception ex)
{
System.out.println(ex.toString())
}
n++
if(n<10)
{
System.out.print("是否继续?(Y/N):")
jixu=('Y'==sc.nextLine().toUpperCase().charAt(0) ?
true : false)
}
}
System.out.printf("这次测试共做了%d题,正确%d题,错误%d题,得分%d",
n,right,wrong,ScorePerExam*right)
System.out.println()
break
case "Q":
exit=true
break
default:
System.out.println("无法处理的菜单命令")
break
}
}
sc.close()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)