对于老师布置的四则运算的题目,以下是我们小组的成果(还有一些不足:如不能连续出题等,以后改进):
#include<stdlib.h> #include<stdio.h> #include<time.h> #include"math.h" #include<conio.h> void main() { int a,b,c,d,e,r,i,v,an; char ch1[4]={'+','-','*','/'}; char ch2[4]={'+','-','*','/'}; for(i=0;i<10;i++) { a=rand()%100; b=rand()%100; c=rand()%100; d=rand()%4; e=rand()%4; printf("%d %c %d %c %d",a,ch1[d],b,ch2[e],c); printf("="); if((ch1[d]=='+'||'-')&&(ch2[e]=='*'||'/')) { if(e==2) { v=c*b; } if(e==3) { v=b/c; } if(d==0) { r=a+v; } if(d==1) { r=a-v; } } else { if(d==0) { v=a+b; } if(d==1) { v=a-b; } if(d==2) { v=a*b; } if(d==3) { v=a/b; } if(e==0) { r=v+c; } if(e==1) { r=v-c; } if(e==2) { r=v*c; } if(e==3) { r=v/c; } } loop:scanf("%d",&an); if(an==r) { printf("OK!"); } else { printf("it does not matter and try it again:"); goto loop; } } }