• 练习一:四则运算


    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    void main()
    {
        int a,b,c,d;
        int total1=0,total2=0;
        while(1)
        {
           srand(time(NULL));
           d=a=rand()%100;
           b=(rand()%a+a)%100;
           if(a%4==1&&a<b)c=a,a=b,b=c;
           if(b==0&&a%4==3)b=rand()%10+1;
           if(a%4==3&&a%b!=0)
           {
               srand(time(0));
               a=b*(rand()%a);
           }
         switch(d%4)
         {
          case 0:printf("%d + %d = ",a,b);break;
          case 1:printf("%d - %d = ",a,b);break;
          case 2:printf("%d × %d = ",a,b);break;
          case 3:printf("%d ÷ %d = ",a,b);break;
         }
         scanf("%d",&c);
         switch(d%4)
         {
         case 0:if(c==a+b){printf("正确\n");total1++;}else {printf("错误!正确答案是%d\n",a+b);total2++;}break;
         case 1:if(c==a-b){printf("正确\n");total1++;}else {printf("错误!正确答案是%d\n",a-b);total2++;}break;
         case 2:if(c==a*b){printf("正确\n");total1++;}else {printf("错误!正确答案是%d\n",a*b);total2++;}break;
         case 3:if(c==a/b){printf("正确\n");total1++;}else {printf("错误!正确答案是%d\n",a/b);total2++;}break;
         }
         printf("按任意键继续,q退出!\n");
         fflush(stdin);
         if(getchar()=='q')break;
        }
        printf("你答对了%d道题,答错%d道题\n",total1,total2);
    }
  • 相关阅读:
    HTTP方法(转)(学习基础)
    正则表达式 学习手记 111221
    原型模式 学习手记
    分布式事务 MSDTC配置
    Ibatis.Net 学习手记二 缓存
    IIS 7.0 部署MVC
    事务与分布式事务
    Ibatis+MVC 3.0 开发手记
    Ibatis.Net 学习手记一 简单的Demo
    简单工厂 学习手记
  • 原文地址:https://www.cnblogs.com/chenjianding/p/4371509.html
Copyright © 2020-2023  润新知