给一个C语言加减乘除的小程序增加一个小功能,使他最后能够统计出正确题目的数量

给一个C语言加减乘除的小程序增加一个小功能,使他最后能够统计出正确题目的数量,第1张

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

static int a,b,sign,result

int fun(){

a = rand()%100+1

b = rand()%100+1

sign = rand()%4

switch(sign){

case 0:

result = a+b

printf("%d+%d=?\n",a,b)

break

case 1:

result = a-b

printf("%d-%d=?\n",a,b)

break

case 2:

result = a*b

printf("%d*%d=?\n",a,b)

break

case 3:

result = a/b

printf("%d/%d=?\n",a,b)

break

}

return result

}

void main(){

int i,flag=0,answer

for(i = 0i<消拍10i++){

fun()

printf("enter the answer\n")

scanf("%d",&answer)

if(answer == result)

flag++

}

printf("Your Answer is%d",10*flag)

}

大致销滚的意思就是这亏桥余样了 而且能跑了

具体的小细节你可以改改

楼主好运

#include<渣侍stdio.h>

#include<stdlib.h>

main()

{

float a,b,rechar c printf("input(like 12+15 or 12*15):\n"氏橘) scanf("%f",&a)

do{

scanf("%c",&c)}while(c == ' ')scanf("%f",&b) switch(c)

{

case '+': re = a+bbreakcase '-': re = a-bbreakcase '*': re = a*bcase '歼梁团/': re = a/bdefault: break

}

printf("output the result:%.1f\n",re)system("pause")

}

输入示例: 2+3(or 2*3 or 2-3 or 2/3)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8284483.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存