本文介绍了如何计算100/30 ans是10/3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

请给我任何解决方案

如果我将100除以30然后答案是3.3333但我想要10/3

Hello
please give me any solution
if i divide 100 by 30 then answer is 3.3333 but i want 10/3

推荐答案


using System.Numerics;



然后,使用此代码:


And then, use this code:

string input = "100/30";
string[] numbers = input.Split('/');
int numerator;
int denominator;
if (numbers.Length == 2 && int.TryParse(numbers[0], out numerator) && int.TryParse(numbers[1], out denominator))
{
    BigInteger gcd = BigInteger.GreatestCommonDivisor(new BigInteger(numerator), new BigInteger(denominator));
    int gcdInt = (int)gcd;
    int newNumerator = numerator / gcdInt;
    int newDenominator = denominator / gcdInt;
    string result = String.Concat(newNumerator, "/", newDenominator);
}
else
{
    // invalid input
}


int GCF(int a, int b)
        {
            int Remainder;

            while (b != 0)
            {
                Remainder = a % b;
                a = b;
                b = Remainder;
            }

            return a;
        }





然后你的结果是





Then Your Result is

<pre>int a=100, b=30;

int gcf = GCF(a,b);

lblResult.Text = (a / gcf) + &quot;/&quot; + (b / gcf);

</pre>





结果:10/3



谢谢



Siva Rm K



Result : 10 / 3

Thanks

Siva Rm K


这篇关于如何计算100/30 ans是10/3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 06:34