标签:
#include<stdio.h> #include<stdlib.h> #include<time.h> int a[100],b[100]; char c[100],sym[5]={‘+‘,‘-‘,‘*‘,‘/‘,‘!‘}; int answer(int i); void printanswer(int n); void main() { int n,o,count; time_t start,end; int i; char r; srand((unsigned)time(NULL)); while(1) { count=0; printf("输入需要的题目数(0退出):"); scanf("%d",&n); if(n==0) exit(0); start =time(NULL); for(i=0;i<n;i++) { a[i]=rand()%201-100; b[i]=rand()%201-100; c[i]=sym[rand()%5]; if(c[i]==sym[4]) { while(a[i]<=0){ a[i]=rand()%201-100; } printf("%d!=",a[i]); } else if(a[i]<0&&b[i]<0) printf("(%d)%c(%d)=",a[i],c[i],b[i]); else if(a[i]<0&&b[i]>0) printf("(%d)%c%d=",a[i],c[i],b[i]); else if(a[i]>0&&b[i]<0) printf("%d%c(%d)=",a[i],c[i],b[i]); else printf("%d%c%d=",a[i],c[i],b[i]); scanf("%d",&o); if(o==answer(i)) { printf("正确!\n"); count++; } else printf("错误!答案是%d\n",answer(i)); } end =time(NULL); printf("答对了%d题,答错了%d题,",count,n-count); printf("用时为%d秒\n",end-start); } } int answer(int i) { int o; if(c[i]==sym[0]) o=a[i]+b[i]; if(c[i]==sym[1]) o=a[i]-b[i]; if(c[i]==sym[2]) o=a[i]*b[i]; if(c[i]==sym[3]) o=a[i]/b[i]; if(c[i]==sym[4]){ o=a[i]; for(i=a[i];i>0;i--) o=o*(o-1); } return o; }
标签:
原文地址:http://www.cnblogs.com/poipoi/p/4398854.html