Home  >  Article  >  Backend Development  >  201306114357-Experiment 1

201306114357-Experiment 1

WBOY
WBOYOriginal
2016-08-08 09:26:49935browse

#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("答案错误,答案为%dn",resultTrue);
  }
  if(resultTrue==n)
  {
   printf("答案正确n");
  }
  }
  if(n==10000)
  {
   return;
  }
 }while(1);
}

以上就介绍了201306114357-实验1,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

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
Previous article:PHP Token (token) designNext article:PHP Token (token) design