修改过的四则运算

#include <stdio.h>
#include <stdlib.h>
main(){
{int i; 
int s=0;
int f;
int count=0;
char c;
printf("请计算以下10题,每题10分:\n");

for(i=0;i<10;i++)
{
 int a=rand()%100;
 int b=rand()%100;
 int  d=rand()%4 ;

 switch(d){
 case 0:
  c='+';
  s=a+b;
  printf("%d %c %d=",a,c,b);
   scanf("%d",&f);
  if(f==s)
  {
   printf("回答正确!\n");
   count++;
  }
   else
   printf("回答错误!\n");
   getchar();
  break;
 case 1:
  c='-4';
  s=b-a;
  printf("%d %c %d=",b,c,a);
   scanf("%d",&f);
  if(f==s)
  {
   printf("回答正确!\n");
        count++;
  }
  else
  {
   printf("回答错误!\n");
  } getchar();
  break;
  case 2:
  c='/';
  s=a/b;
  if(a%b!=0){
   printf("该题有余数。答案只要整数部分!");
  }
  printf("%d %c %d=",a,c,b);
   scanf("%d",&f);
  if(f==s)
  { printf("回答正确!\n");
  count++;
  }
  else
   printf("回答错误!\n");
  break;
  case 3:
  c='*';
  s=a*b;
  printf("%d %c %d=",a,c,b);
          scanf("%d",&f);
  if(f==s)
  { printf("回答正确!\n");
         count++;
  }
  else
   printf("回答错误!\n");
  break;
 }
}

printf("恭喜你答对了%d题",count);
}
}

答案只能是整数。没有判断是否负数功能。

posted @ 2015-04-01 16:04  48练丽云  阅读(131)  评论(0编辑  收藏  举报