码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算题的输出

时间:2016-03-07 22:24:10      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:

源代码://四则运算
//邵文正 20142894  2016.3.7
#include<iostream>
using namespace std;
int random()
     {
        return(rand()%100);
     }
char Fuhao()
     {
        int a;
       a = rand() % 4;
       if (a == 1)
    {
          return ‘+‘;
    }
     if (a == 2)
    {
          return ‘-‘;
    }
    if (a == 3)
    {
        return‘*‘;
    }
    else
    {
        return‘/‘;
    }
}
void Jiafenshu()
{
      int x, y;
      m:y = rand() % 10;
    if (y == 0)
    {
          goto m;
    }
    x = rand() % 100;
    cout <<"("<< x << "/" << y<<")" ;
}
void main()
{
      int a, b;
    
      cout << "以下是30个四则运算不包含假分数\n" << endl;
      for (int i = 0; i < 30; i++)
    {
          x:a = random();
          b = random();
          Fuhao();
          if (Fuhao() == ‘/‘ || b == 0)
        {
              goto x;
        }
             cout << a << Fuhao() << b << "=   " << endl;
    }
       cout << "以下是假分数的运算30个:\n" << endl;
    for (int i = 0; i < 30; i++)
    {
        Jiafenshu();
        cout << Fuhao();
        Jiafenshu();
        cout <<"=  "<< endl;
    }
      
}

程序运行结果截图:技术分享

四则运算题的输出

标签:

原文地址:http://www.cnblogs.com/aishangtaxuefeihong/p/5252054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!