如何化简分数

发布于 2024-12-10 01:11:55 字数 85 浏览 0 评论 0原文

我想简化我的应用程序中的一部分。分数就像, x/y 其中 x 和 y 是整数。 我想将分数简化为最简单的形式。 任何人都可以给我提示如何去做。 提前致谢。

I want to simplify a fraction in my application. The fraction is like,
x/y where x and y are integers.
I want to simplify the fraction to its simplest form.
Can anyone please give me hints how to do it.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温暖的光 2024-12-17 01:11:55
  • 计算 x 和 y 的最大公约数
  • 将它们除以 GCD

欧几里德算法 是计算 GCD 的简单方法。

  • Compute the greatest common divisor for x and y
  • Divide both of them by the GCD

Euclid's algorithm is an easy way to compute the GCD.

窗影残 2024-12-17 01:11:55

将两者除以 gcd(x,y)

二元 GCD 算法是计算 GCD 的快速方法在计算机上。

Divide both by gcd(x,y)

The Binary GCD algorithm is a fast way to compute the GCD on a computer.

一人独醉 2024-12-17 01:11:55
     #include<iostream>
      using namespace std;
        struct fraction
        {
              int n1, d1, n2, d2, s1, s2;
             };
         void simplification(int a,int b)
       {
                bool e = true;
            int t; int z;
        for (int i = (a*b); i > 1;i--)
        { if ((a%i==0)&&(b%i==0))
       {
        t = a / i;
      z = b / i;

         }
else
         {
            e = false;
       }
         }
         cout << "simplest form=" << t << "/" << z << endl;

      }
      void sum(int num1, int deno1, int num2, int deno2)
        {
            int k,y;
          k = num1* deno2 + num2*deno1;
          y = deno2*deno1;
           cout << "addition of given fraction = " << k << "/" << y << endl;
         simplification(k, y);
      }
     void sub(int num1, int deno1, int num2, int deno2)
     {              
           int k, y;

            k = num1*deno2 - num2*deno1;
        y = deno1*deno2;
            cout << "Substraction of given fraction = " << k << "/" << y << endl;

          }
         void mul(int num1, int deno1, int num2, int deno2)
            {
            int k, y;

            k = num1*num2;
                y = deno1*deno2;
                 cout << "multiplication of given fration= " << k<< "/" <<y;                                        cout<< endl;
                simplification(k, y);
            }

        void div(int num1, int deno1, int num2, int deno2)
          {
          int k, y;
       ;
     k = num1*deno1;
     y = deno1*num2;
        cout << "division of given fraction" << k << "/" << y << endl;
    simplification(k, y);
     }


      int main()
       {    fraction a;
            cout << "enter numirator of f1=";cin >> a.n1;
          cout << "enter denominator of f1=";cin >> a.d1;
            cout << "enter numirator of f2=";cin >> a.n2;
        cout << "enter denominator of f2=";cin >> a.d2;
            cout << "f1= " << a.n1 << "/" << a.d1 << endl;
                cout << "f2= " << a.n2 << "/" << a.d2 << endl;
            mul(a.n1, a.d1, a.n2, a.d2);
        div(a.n1, a.d1, a.n2, a.d2); 
                sub(a.n1, a.d1, a.n2, a.d2);
                sum(a.n1, a.d1, a.n2, a.d2);
         system("pause");
           }
     #include<iostream>
      using namespace std;
        struct fraction
        {
              int n1, d1, n2, d2, s1, s2;
             };
         void simplification(int a,int b)
       {
                bool e = true;
            int t; int z;
        for (int i = (a*b); i > 1;i--)
        { if ((a%i==0)&&(b%i==0))
       {
        t = a / i;
      z = b / i;

         }
else
         {
            e = false;
       }
         }
         cout << "simplest form=" << t << "/" << z << endl;

      }
      void sum(int num1, int deno1, int num2, int deno2)
        {
            int k,y;
          k = num1* deno2 + num2*deno1;
          y = deno2*deno1;
           cout << "addition of given fraction = " << k << "/" << y << endl;
         simplification(k, y);
      }
     void sub(int num1, int deno1, int num2, int deno2)
     {              
           int k, y;

            k = num1*deno2 - num2*deno1;
        y = deno1*deno2;
            cout << "Substraction of given fraction = " << k << "/" << y << endl;

          }
         void mul(int num1, int deno1, int num2, int deno2)
            {
            int k, y;

            k = num1*num2;
                y = deno1*deno2;
                 cout << "multiplication of given fration= " << k<< "/" <<y;                                        cout<< endl;
                simplification(k, y);
            }

        void div(int num1, int deno1, int num2, int deno2)
          {
          int k, y;
       ;
     k = num1*deno1;
     y = deno1*num2;
        cout << "division of given fraction" << k << "/" << y << endl;
    simplification(k, y);
     }


      int main()
       {    fraction a;
            cout << "enter numirator of f1=";cin >> a.n1;
          cout << "enter denominator of f1=";cin >> a.d1;
            cout << "enter numirator of f2=";cin >> a.n2;
        cout << "enter denominator of f2=";cin >> a.d2;
            cout << "f1= " << a.n1 << "/" << a.d1 << endl;
                cout << "f2= " << a.n2 << "/" << a.d2 << endl;
            mul(a.n1, a.d1, a.n2, a.d2);
        div(a.n1, a.d1, a.n2, a.d2); 
                sub(a.n1, a.d1, a.n2, a.d2);
                sum(a.n1, a.d1, a.n2, a.d2);
         system("pause");
           }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文