56 小易
欢迎来到小易的博客

 

#include<stdio.h>
#include <ctype.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
int a[100],b[100];
int h;
char c[100],sym[5]={'+','-','*','/','!'};
int answer(int i);
void printanswer(int n);
void main()
{
    int o,count;
 int n;
 long k=-10001;
    time_t start,end;
    int i;
    char r;
       srand((unsigned)time(NULL));
        while(1)
        {
            count=0;
            printf("\t\t\t请输入题数 (0表示退出)");
            n=-1;
            scanf("%d",&n);
   while(1){
    if(n<0){
     fflush(stdin);
     printf("输入有误 请重新输入");
                    scanf("%d",&n);
    }else{break;}
   }
            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]>10){
                   a[i]=rand()%10;
                }
                printf("%d!=",a[i]);
    h=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",&k);
   while(1){
    if(k==-10001){
     fflush(stdin);
     printf("输入有误 请重新输入 ");
                    scanf("%d",&k);
    }else{break;}
   }
            if(k==answer(i)) {
                printf("正确!\n");
    k=-10001;
                count++;
            }
            else {
    printf("输入有误 请重新输入%d\n",answer(i));
    k=-10001;
   }
            }
            end =time(NULL);
            printf("恭喜你对了%d题,一共有%d题,",count,n-count);
            printf("你一共花了%d秒\n",end-start); 
        }
}
int answer(int i)
{
    long 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=1;
            for(i=1;i<=h;i++)
                o=o*i;
        }
        return o;
}



 

 

 

 

我们的作业弄得比较简单得弄了四个功能,修改花了半个小时,让程序变得简单。 不过我发现会出现阶乘,小学题目没有阶乘,不过阶乘有些意思就用了,还有按成符号会死循环,经过我稍微修改,按符号不会死循环了,但是它会让接下来的所有题目都答0然后显示错误。

结对同伴:

 

姓名

学号

博客地址

领航员       侯圣燊

201306114402

 

http://home.cnblogs.com/u/sihouzi/

 

驾驶员          刁怿

201306114456

http://home.cnblogs.com/u/diaoyi/

 

 

     

posted on 2015-04-09 10:41  56小易  阅读(196)  评论(0编辑  收藏  举报