计算机编程教学系统,c语言编程作业小学生计算机辅助教学系统

匿名用户

1级

2016-11-27 回答

#include 

#include 

#ifndef RedContritio

#include 

#else

#message("This is RedContritio's energy")

#endif

#include  //用到了time函数

int jia(int a,int b) {

return a+b;

}

char solutation[999] = "\0";

int jian(int a,int b) {

return a-b;

}

int cheng(int a,int b) {

return a*b;

}

float chu(int a,int b) {

return 1.0*a/b;

}

int solve(int a,int b,int c) {

if(c==1)return jia(a,b);

if(c==2)return jian(a,b);

if(c==3)return cheng(a,b);

if(c==4)return (int)chu(a,b);

}

int main() {

int a,b,c,answer;

char cmd;

srand(time(NULL)); //用时间做种,每次产生随机数不一样

printf("enter to start,-1 to quit:");

while((cmd=getchar())!='-') {

a = rand() % 10+1;  //产生1-10的随机数

b= rand() % 10+1;

c= rand() %4+1;

answer=solve(a,b,c);

char ys;

switch(c) {

case 1:

ys='+';

break;

case 2:

ys='-';

break;

case 3:

ys='*';

break;

case 4:

ys='/';

break;

}

printf("%d %c %d = ?\n",a,ys,b);

int r=0,solution;

while(!r) {

printf("please input your answer.\n");

memset(solutation,0,sizeof(solutation));

scanf("%s",solutation);

solution = atoi(solutation);

if(!(solution-answer)) { //除法出现小数这里是向下取整,不是四舍五入

puts("Right!");

r=1;

} else puts("Wrong!Please try again.");

}

printf("continue?(-1 to quit):");

getchar();//处理缓冲区的多余回车

}

return 0;

}望采纳,多余的printf是为了增强交互性,不需要可删掉。另除法不是很完善,自己可规定小数精度,对代码进行修改。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值