用C函数编一个四则运算的小程序(要编译能通过的

用C函数编一个四则运算的小程序(要编译能通过的,第1张

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

void main()

{ int a,b,i,c,d,p=1,m=0,n=0

a=rand()%100b=rand()%100

for(i=0i<10i++)

printf("*")

printf("\n* 1.加法 *\n")

printf("\n* 2.减法 *\n")

printf("\n* 3.乘法 *\n")

printf("\n* 4.除法 *\n")

for(i=0i<10i++)

printf("*")

while(p)

{ printf("\n请选择 *** 作n(1-6):")

scanf("%d",&c)

c=c%6

printf("\n请输入答案:\n")

switch(c)

{ case 0:exit(1)

case 1:c='+'printf("%d+%d=\n",a,b)scanf("%d",&d)

while(m<3&&p)

{if(d==a+b)<br/>{printf("good,你的答案是正确的")<br/> n++p=0}

else

printf("\n对不起,你的答案是错误的\n请输入正确答案:\n%d+%d=\n",a,b)

m++scanf("%d",&d) } p=1

break

case 2:c='-'printf("%d-%d=\n",a,b)

scanf("%d",&d)

while(m<3&&p)

{if(d==a-b)<br/>{printf("good,你的答案是正确的")<br/> n++p=0}

else

printf("\n对不起,你的答案是错误的\n请输入正确答案:\n%d-%d=\n",a,b)

m++scanf("%d",&d)} p=1

break

case 3:c='*'printf("%d*%d=\n",a,b)

scanf("%d",&d)

while(m<3&&p)

{if(d==a*b)<br/>{printf("good,你的答案是正确的")<br/> n++p=0}

else

printf("\n对不起,你的答案是错误的\n请输入正确答案:\n%d*%d=\n",a,b)

m++scanf("%d",&d)} p=1

break

case 4:c='/'printf("%f/%f=\n",(float)a,(float)b)

scanf("%d",&d)

while(m<3&&p)

{if(d==(float)a/(float)b)<br/>{printf("good,你的答案是正确的")<br/> n++p=0}

else

printf("\n对不起,你的答案是错误的\n请输入正确答案:\n%d-%d=\n",a,b)

m++scanf("%d",&d)} p=1break

case 5:printf("\n你一共做对了%d,错了%d\n",n,m)break

}

}

}

<pre t="code" l="cpp">right_prompt()

{

int x

x = rand()%4+1

switch(x) {

case 1:

printf("Very Good!\n")

break

case 2:

printf("Excellent!\n")

break

case 3:

printf("Nice work!\n")

break

case 4:

printf("Keep up the good work!\n")

break

}

}

wrong_prompt()

{

int x

x = rand()%4+1

switch(x) {

case 1:

printf("No. Please try again.\n")

break

case 2:

printf("Wrong. Try once more.\n")

break

case 3:

printf("Don’t give up!\n")

break

case 4:

printf("Not correct. Keep trying.\n")

break

}

}


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

原文地址: http://outofmemory.cn/yw/11386757.html

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

发表评论

登录后才能评论

评论列表(0条)

保存