博客班级 https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19
作业要求 https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/homework/11376
作业目标 写一个能自动生成小学四则运算题目的程序
学号 3190704102
`package daolunzuoye1026;
import java.util.Random;
import java.util.Scanner;
public class daolun {
public static void main(String[] args) {
int e = 0, r = 0;
System.out.println("欢迎来到四则运算测试软件!");
System.out.println("做题前请认真读题,祝您考试愉快!");
Random r1 = new Random();
for (int i = 0; i < 7; i++) {
int m, n;
int a, b, c;
m = r1.nextInt() % 10;
n = m % 4;
C语言实现
`#include<stdio.h>
include<math.h>
include<windows.h>
int right=0;
int wrong=0;
void jia()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:\n\t\t %d + %d = ",a,b);
scanf("%d",&c);
if(a+bc)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void jian()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:\n\t\t %d - %d = ",a,b);
scanf("%d",&c);
if(a-bc)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void cheng()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:\n\t\t %d * %d = ",a,b);
scanf("%d",&c);
if(abc)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void chu()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:\n\t\t %d / %d = ",a,b);
scanf("%d",&c);
if(a/b*c)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void main()
{
int choise;
int cho=0;
printf("\n\t\t\t欢迎进入小学简易四则运算\n\n");
while(1)
{
printf("请选择:\n");
printf("\t\t\t 加法运算(请输入1)\n");
printf("\t\t\t 减法运算(请输入2)\n");
printf("\t\t\t 乘法运算(请输入3)\n");
printf("\t\t\t 除法运算(请输入4)\n");
printf("\t\t\t 退出运算(请输入5)\n");
if(cho0)
scanf("%d",&choise);
switch(choise)
{
case 1:
jia();
break;
case 2:
jian();
break;
case 3:
cheng();
break;
case 4:
chu();
break;
case 5:
return;
}
printf("\n\t\t\t继续运算?(请输入1)\n");
printf("\n\t\t\t重新选择?(请输入2)\n");
printf("\n\t\t\t退出运算?(请输入3)\n");
scanf("%d",&cho);
if(cho1)
cho=1;
else if(cho2)
cho=0;
else if(cho3)
break;
else
printf("抱歉!,你输入的指令有误!请重新输入!\n");
}
printf("您总共完成了 %d 道题\n正确 %d 道\n错误 %d 道\n",right+wrong,right,wrong);
}`
表格如下