zoukankan      html  css  js  c++  java
  • 简单四则运算

    #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 ! ");
        }
    }
     
    }
  • 相关阅读:
    Windows 2012 安装 SQL Server 2012,.Net Framework 3.5安装不成的解决办法
    HTML+CSS 对于英文单词强制换行但不截断单词的解决办法
    删除N天前的文件(夹)与拷贝文件到共享盘的批处理
    npm 常用命令
    使用scrapy crawl name启动一个爬虫时出现的问题
    anaconda和pycharm环境交叉的现象
    list和range()函数中使用反向索引的方法
    关于一些术语的解释
    关于assert和de-assert的解释
    搭建eclipse4.6(neon) + Pydev5.8.0 + python3.6(小版本3.6.1)
  • 原文地址:https://www.cnblogs.com/tangruo/p/8622069.html
Copyright © 2011-2022 走看看