*/
include<stdio.h>
include
include <stdlib.h>
include <time.h>
using namespace std;
//下面的代码根据算法笔记A1081 分数的四则运算修改而得
typedef long long ll;
int ans4,ans5,ans6;//带分数
ll gcd(ll a,ll b){//求最大公约数的辗转相除法递归写法
return b==0?a:gcd(b,a%b);
}
struct Fraction{//分数
ll up,down;//分子,分母
};
Fraction reduction(Fraction result){//分数的化简
if(result.down<0){
result.down=-result.down;
result.up=-result.up;
}
if(result.up==0){
result.down=1;
}else{
int d=gcd(abs(result.up),abs(result.down));
result.down/=d;
result.up/=d;
}
return result;
}
//分数的加减乘除
Fraction add(Fraction f1,Fraction f2){
Fraction result;
result.up=f1.upf2.down+f2.up f1.down;
result.down=f1.downf2.down;
return reduction(result);
}
Fraction minu(Fraction f1,Fraction f2){
Fraction result;
result.up=f1.upf2.down-f2.up f1.down;
result.down=f1.downf2.down;
return reduction(result);
}
Fraction multi(Fraction f1,Fraction f2){
Fraction result;
result.up=f1.upf2.up;
result.down=f1.downf2.down;
return reduction(result);
}
Fraction divide(Fraction f1,Fraction f2){
Fraction result;
result.up=f1.upf2.down;
result.down=f1.downf2.up;
return reduction(result);
}
//分数的输出
void showResult(Fraction r){
reduction(r);
if(r.down==1) printf("%lld
",r.up);
else if(abs(r.up)>r.down){//假分数
ans4=r.up/r.down;
ans5=abs(r.up)%r.down;
ans6=r.down;
}else{//真分数
ans4=0;
ans5=r.up;
ans6=r.down;
}
}
int ans;
int ans1;//除法所得结果整数部分
int ans2;//除法所得结果余数部分
double ans3;//(a/b/c类型的答案以3位小数展现)
int a1[100],b1[100],c1[100];//10以内整数
int main(){
Fraction sum,sum2,temp,sum3,sum4;
sum.up=0;
sum.down=1;
sum2.up=0;
sum2.down=1;
sum3.up=1;
sum3.down=1;
sum4.up=1;
sum4.down=1;
int right=0;
int wrong=0;
int grade;
int degree;//3 Difficulty level,respectively are difficult=3 medium=2 easy=1
int num;//题目数量
printf("请输入你的年级,一年级输入1,二年级输入2,三年级输入3,四年级输入4,五年级输入5
");
scanf("%d",&grade);
printf("请选择难易程度,选择简单输入1,选择中等输入2,选择困难输入3
");
scanf("%d",°ree);
switch(grade){
case 1:
if(degree==1){
printf("这是一年级运算简单程度
");
printf("请输入题目数量
");
scanf("%d",&num);
srand((unsigned) (time(NULL)));
for(int i=0;i<num;i++){
int n1=rand()%10;
int n2=rand()%10;
if(n1>=n2){
a1[i]=n1;
b1[i]=n2;
}
else{
a1[i]=n2;
b1[i]=n1;
}
}
for(int i=0;i<num/2;i++){
printf(" %d + %d =
",a1[i],b1[i]);
scanf("%d",&ans);
if(a1[i]+b1[i]==ans){
printf("回答正确!
");
right++;
}
else{
printf("回答错误!
");
wrong++;
}
}
for(int i=num/2;i<num;i++){
printf("
%d -%d = ",a1[i],b1[i]);
scanf("%d",&ans);
if(a1[i]-b1[i]==ans){
printf("回答正确!
");
right++;
}
else{
printf("回答错误!
");
wrong++;
}
}
printf("你一共答对了%d道题,答错了%d道题
",right,wrong);
}
else if(degree==2){printf("这是一年级运算中等程度");
printf("请输入题目数量
");
scanf("%d",&num);
for(int i=0;i<num;){
int n1=rand()%10;
int n2=rand()%10;
int n3=rand()%10;
if(n1+n2-n3>=0&&n1+n3-n2>=0){
a1[i]=n1;
b1[i]=n2;
c1[i]=n3;
i++;}
}
for(int i=0;i<num/2;i++){
printf(" %d + %d -%d=
",a1[i],b1[i],c1[i]);
scanf("%d",&ans);
if(a1[i]+b1[i]-c1[i]==ans){
printf("回答正确!
");
right++;}
else{
printf("回答错误!
");
wrong++;}
}
for(int i=num/2;i<num;i++){
printf("
%d -%d +%d= ",a1[i],b1[i],c1[i]);
scanf("%d",&ans);
if(a1[i]-b