作业—四则运算题目生成器

代码来源:网上查找并修改(具体网址忘记了)

程序功能:在用户选择某一类算法后,可自行随机出题,并在之后选择查看答案和退出

编译环境:C语言

运行平台:Windows

BUG:只能支持整数,不支持分数

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main()
{
int a,b,op,os;

printf(" [四则运算挑战系统]\n");
aq1: printf("选择你想挑战的运算法则\n");
printf("1.加法 2.减法 3.乘法 4.除法\n");
scanf("%d",&op);
switch(op)
{
aq: case 1:
srand((unsigned)time(NULL));
a=rand()%100+1;b=rand()%100+1;
printf("题目为:%d + %d = ?\n\n",a,b);
printf("1.查看答案 2.做下一题\n");
scanf("%d",&os);
if(os==1)
{printf("%d + %d =%d\n\n\n",a,b,a+b);
goto aq1;
}
else
goto aq;
break;
at: case 2:a=rand()%100+1;b=rand()%100+1;
printf("题目为:%d - %d = ?\n\n",a,b);
printf("1.查看答案 2.做下一题\n");
scanf("%d",&os);
if(os==1)
{printf("%d - %d =%d\n\n\n",a,b,a-b);
goto aq1;
}
else
goto at;
break;
aq2: case 3:
a=rand()%100+1;b=rand()%100+1;
printf("题目为:%d * %d = ?\n\n",a,b);
printf("1.查看答案 2.做下一题\n");
scanf("%d",&os);
if(os==1)
{printf("%d * %d =%d\n\n\n",a,b,a*b);
goto aq1;
}
else
goto aq2;
aq3: case 4:
a=rand()%100+1;b=rand()%100+1;
printf("题目为:%d / %d = ?\n\n",a,b);
printf("1.查看答案 2.做下一题\n");
scanf("%d",&os);
if(os==1)
{printf("%d / %d =%d\n\n\n",a,b,a/b);
goto aq1;
}
else
goto aq3;
break;
}
}

转载于:https://www.cnblogs.com/mjl4396/p/7608365.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值