Home  >  Article  >  Backend Development  >  201306114357-实验一

201306114357-实验一

WBOY
WBOYOriginal
2016-06-13 12:17:14694browse

201306114357-实验1

#include
#include
#include
main()
{
 int a,b,c;
 float resultTrue=0,n;
 char op;
 srand(time(NULL));
 do
 {
  a=rand()%10+1;
  b=rand()%10+1;
  c=rand()%4+1;
  switch(c%4)
  {
  case 0:
   {
    op='+';
    break;
   }
  case 1:
   {
    op='-';
    break;
   }
  case 2:
   {
    op='*';
    break;
   }
  case 3:
   {
    op='/';
    break;
   }
  }
  printf("%d%c%d=\n",a,op,b);
  switch(op)
  {
   case '+':
   {
    resultTrue=a+b;
    break;
   }
   case '-':
    {
     resultTrue=a-b;
     break;
    }
   case '*':
    {
     resultTrue=a*b;
     break;
    }
   case '/':
    {
     resultTrue=a/b;
     break;
    }
  }
  printf("请输入正确答案(1000为结束):");
  scanf("%f",&n);
  if(n!=0)
  {
  if(resultTrue!=n)
  {
   printf("答案错误,答案为%d\n",resultTrue);
  }
  if(resultTrue==n)
  {
   printf("答案正确\n");
  }
  }
  if(n==10000)
  {
   return;
  }
 }while(1);
}

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn