• 简单四则运算


    #include<iostream>
    using namespace std;
    void main()
    {
    int i,x,y,z;
    for(i=1;i<=30;i++)
    {
    x=rand()%99;
    y=rand()%99;
    z=(x+y)%4;
    if(z==0)
    cout<<i<<":<<x<<"+"<<y<<"="<<endl;
    if(z==1)
    cout<<i<<":<<x<<"-"<<y<<"="<<endl;
    if(z==2)
    cout<<i<<":<<x<<"*"<<y<<"y"<<endl;
    if(z==3)
    cout<<i<<":<<x<<"/"<<y<<"y"<<endl;
    }
    }

      

    <br>#include<iostream>
    #include<stdio.h>
    #include<time.h>
    #include<stdlib.h>
    #include<conio.h>
    using namespace std;
    void main()
    {
         int i,j,x,y,z,w,q,r;//q商,r余数,w交换
         int answer[100],grade;
         srand((unsigned)time(NULL));
         for(i=1;i<=30;i++)
         {
            x=rand()%99;  //产生随机数x为第一位数
            y=rand()%99;  //产生随机数y为第二位数
            z=rand()%4; //z用来确定随机产生的运算符号
            if(z==0)//输出算术式
            cout<<i<<":"<<x<<"+"<<y<<"="<<endl;
     
            if(z==1)
            
                if(x<y) { w=x;x=y;y=w;}
               cout<<i<<":"<<x<<"-"<<y<<"="<<endl;
            }
            if(z==2)
            cout<<i<<":"<<x<<"*"<<y<<"="<<endl;
     
            if(z==3)
            {
               if(y==0)     y=1;
               cout<<i<<":"<<x<<"/"<<y<<"="<<endl;
            }
            switch(z)
            {
                case 0:
                       answer[z]=x+y;
                       break;
                case 1:
                       answer[z]=x-y;
                       break;
               case 2:
                       answer[z]=x*y;
                       break;
               case 3:
                       printf(" quotient= ");
                       scanf("%d",&q);
                       printf(" remainder=");
                       scanf("%d",&r);
                       for(j=9;j>1;j++)
                       {
                         if((x%j==0)&&(y%j==0))
                         { x=x/j;y=y/j;}
                       }
                      if( (q==x/y)&&(r==x%y))
                      {
                        grade+=1;
                        printf("You are right ! ");
                      }
                      else
                     printf("You are wrong ! ");
                     break;
     }
          
        if(z<3)
        {
            scanf("%d",&q);
            if(q==answer[z])
            {
                grade+=1;
                printf("You are right ! ");
            }
            else
                printf("You are wrong ! ");
        }
    }
     
    }
  • 相关阅读:
    redis接入sentinelPool的配置
    02.Redis主从集群的Sentinel配置
    淘宝大秒系统设计详解
    关于Thread.currentThread()和this的差异
    App开放接口api安全性—Token签名sign的设计与实现
    使用Spring Session做分布式会话管理
    PowerDesigner 15.1 安装步骤详细图解及破解
    解密ThreadLocal
    深入分析 ThreadLocal 内存泄漏问题
    一个经典例子让你彻彻底底理解java回调机制
  • 原文地址:https://www.cnblogs.com/tangruo/p/8622069.html
Copyright © 2020-2023  润新知