zoukankan      html  css  js  c++  java
  • 修改过的四则运算

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

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

  • 相关阅读:
    2、MapStruct 深入理解
    1、MapStruct的应用
    Spring中的注解
    java中的三个内置注解
    依赖注入集合属性
    List Set Map的特点
    为类类型的属性依赖注入值
    java常用专业术语
    Bean的作用域范围
    Bean的生命周期
  • 原文地址:https://www.cnblogs.com/Lianliyun/p/4384176.html
Copyright © 2011-2022 走看看