#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;
             }
    }

}

 

posted on 2016-04-19 22:44  于大侠的大侠  阅读(479)  评论(0编辑  收藏  举报