# 算出差值最小的两个乘数 C#

0

3=1*3
6=2*3
8=2*4
12=3*4
15=3*5
18=3*6
24=4*6

1

static Tuple<int, int> GetNeedData(int source)
{
if (source <= 0)
return new Tuple<int, int>(0,0);
int x = 1, y = source;
int t1 = x, t2 = y;
for (; x <= y; x++){

if (source % x == 0)
{
y = source / x;
if(x <= y)
{
t1 = x;
t2 = y;
Console.WriteLine(\$"x:{x},y:{y}");
}

}
}
Console.WriteLine(\$"need-data->x:{t1},y:{t2}");
return new Tuple<int, int>(t1, t2);
}

kingreatwill | 菜鸟二级 |园豆：383 | 2017-02-23 14:12

0

@疯五五爱喝咖啡: 你不会找一个数的约数吗.从2开始求余数.余数为0了就能被整除.

@吴瑞祥: 嗯，确实水平较低，谢谢指导

0
```        static void Main(string[] args)
{
Console.WriteLine("输入一个数字");
int j;
List<int> a = new List<int>();
for (int i = 1; i < number; i++)
{
if (number % i == 0)
{
j = number / i;
}
}
int minnumber = a.Min();  //这个是差值
double number1 = 0;              //第一个乘数
double number2 = 0;              //第二个乘数
double dt = minnumber * minnumber + 4 * number;
if (dt < 0)
{
Console.WriteLine("无解");

}
else if (dt == 0)
{
number1 = Math.Abs(-minnumber / 2 * number);
Console.WriteLine("两个乘数为{0}和{1}", number1, number1);

}
else
{
number1 = Math.Abs((-minnumber + Math.Sqrt(dt)) / 2 );
number2 = Math.Abs((-minnumber - Math.Sqrt(dt)) / 2 );
Console.WriteLine("两个乘数为{0}和{1}", number1, number2);

}
}```

无解

@kingreatwill: 一元二次求根，刚毕业，他的方法比我好，

您需要登录以后才能回答，未注册用户请先注册