用C语言编写小学生四则运算系统

用C语言编写小学生四则运算系统,第1张

#include #include #include int num=0,num1=0; int m[1000][100]; char oper[4]={'+','-','','/'}; int main() { int a,b,c,d,e,flag,i,j; for(i=1;i<=1000;++i) for(j=1;j<=i;++j) if(i%j==0) m[i][m[i][0]++]=j; srand(time(0)); while(1) { system("cls"); printf("当前答题数:%d 正确数:%d 正确率:%2lf%%\n",num,num1,numnum110/num100:0); flag=0; c=rand()%4; while(1) { flag=0; if(c<3) { a=rand()%1000;b=rand()%1000; } else { a=rand()%1000; b=rand()%m[a][0]; b=m[a][b]; } switch(c) { case 0: if(a+b=b) flag=1,d=a-b; break; case 2: if(ab<=1000) flag=1,d=ab; break; case 3: if(a%b==0) flag=1,d=a/b; break; } if(flag) break; } printf("%d%c%d=\n",a,oper[c],b); num++; scanf("%d",&e); if(e==d) { printf("恭喜你回答正确!\n"); num1++; } else { printf("很遗憾,回答错误,正确答案是%d\n",d); } system("pause"); } }

程序如下: #include<stdioh>

#include<stdlibh>

void main()

{

int a[100];

int i=0,j,n;

int x,count=0;

int re,re1;

for(j=0;j<=99;)

{

n=rand();

if(n>0&&n<100)

{

a[j]=n;

j++;

}

}

loop: printf("\t\t\n");

printf("\t\t 菜单 \n");

printf("\t\t 1: 加 \n");

printf("\t\t 2: 减 \n");

printf("\t\t 3: 乘 \n");

printf("\t\t 4: 除 \n");

printf("\t\t 5: 退出 \n");

printf("\t\t\n");

printf("\n请选择菜单:\n");

scanf("%d",&x);

if(1==x)

{

printf("%d + %d = ",a[i],a[i+1]);

scanf("%d",&re1);

re=a[i]+a[i+1];

if(re==re1)

{

printf("答对了!\n");

exit(0);

}

else

{

count++;

printf("答错了,你还有%d次机会!\n",3-count);

}

}

if(2==x)

{

printf("%d - %d = ",a[i],a[i+1]);

scanf("%d",&re1);

re=a[i]-a[i+1];

if(re==re1)

{

printf("答对了!\n");

exit(0);

}

else

{

count++;

printf("答错了,你还有%d次机会!\n",3-count);

}

}

if(3==x)

{

printf("%d %d = ",a[i],a[i+1]);

scanf("%d",&re1);

re=a[i]a[i+1];

if(re==re1)

{

printf("答对了!\n");

exit(0);

}

else

{

count++;

printf("答错了,你还有%d次机会!\n",3-count);

}

}

if(4==x)

{

printf("%d / %d = ",a[i],a[i+1]);

scanf("%d",&re1);

re=a[i]/a[i+1];

if(re==re1)

{

printf("答对了!\n");

exit(0);

}

else

{

count++;

printf("答错了,你还有%d次机会!\n",3-count);

}

}

if(5==x)

exit(0);

if(count<3)

goto loop;

if(3==count)

{

printf("你已经没有机会了!\n");

exit(0);

}

}

有疑问提出。

Dim s1!, s2!, a$ '为小数点的叠加,s1,s2必须定义为单精度型

Dim flag As Boolean 'flag它是过程及的变量,在通用里必须声明

'在数字按钮控件单击数组单击事件中获取 *** 作数(没有区分是哪一个 *** 作数)

Private Sub Command1_Click(Index As Integer)

x = Text1Text

If flag = True Or x = "0" Then '查看数字是否输入完毕或者是否清零了

Text1Text = CStr(Index) 'CStr将数值转换字符

Else

Text1Text = Text1Text + CStr(Index) '"+"在这里这个是对字符串的 *** 作的叠加,CStr(Index)是接的数据

End If

flag = False '时刻准备数字的输入

End Sub

'2单击运算符,确定s1,并且要选定运算

Private Sub Command2_Click(Index As Integer)

flag = True

s1 = Val(Text1Text)

Select Case Index

Case 0

a = "+"

Case 1

a = "-"

Case 2

a = ""

Case 3

a = "/"

End Select

End Sub

'3"="的单击事件

Private Sub Command3_Click()

flag = True

s2 = Val(Text1Text)

Select Case a

Case "+"

Text1Text = s1 + s2

Case "-"

Text1Text = s1 - s2

Case ""

Text1Text = s1 s2

Case "/"

Text1Text = s1 / s2 '分母不能为0

End Select

s1 = 0: s2 = 0: a = ""

End Sub

'4清屏

Private Sub Command4_Click()

Text1Text = "0"

s1 = 0

s2 = 0

a = ""

flag = False

End Sub

'5删除最后输入的一个字符,换句话说,将本文框中的字符串取字符(从左往右取left(string,length)),将最后一个字符不取就先行

Private Sub Command5_Click()

If Text1Text = "" Then

Else

Command5Enabled = True

Text1Text = Left(Text1Text, Len(Text1Text) - 1)

'len求字符串的长度,left(text1len(text1)-1减1是取字符串从左往右减去一个字符串

End If

End Sub

'小数点 1)显示出""(注意前面输入过的整数必须显示) 2)小数后能继续接受数字的输入

Private Sub Command6_Click()

Text1 = Text1 & ""

End Sub

'7加入正负号--单击“+、-”,产生一个"-",而且处于一种等待数字输入的一种状态

Private Sub Command7_Click()

Dim temp As Double

temp = -Val(Text1Text)

Text1Text = temp

If d = " " Then s1 = temp Else s2 = temp

End Sub

Private Sub Command8_Click() '退出

End

End Sub

Private Sub Form_Load() '窗体初始化

Text1Text = 0

Text1Locked = True

End Sub

以上就是关于用C语言编写小学生四则运算系统全部的内容,包括:用C语言编写小学生四则运算系统、如何编写C语言儿童100以内的加减乘除法游戏训练程序、求VB程序代码(小学生四则运算题)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址:https://54852.com/zz/9456611.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存