: 10 20 : 20 10
ref . , , . , , , , . , ref .
out
, . , , , , . , . , ref . , ref, . , C# out.
out ref, : . , out, ( ) - . , out , .. , . , . , out .
out. GetParts () Decompose. , .
// out.
Using System;
class Decompose {
/* . */ public int GetParts(double n, out double frac) { int whole;
whole = (int) n;
frac = n - whole; // frac return whole; //
}
}
class UseOut {
static void Main() {
Decompose ob = new Decompose(); int i; double f;
i = ob.GetParts(10.125, out f);
Console.WriteLine(" " + i);
Console.WriteLine(" " + f);
}
}
.
10 0.125
Get Parts () . -, return. -, f out. , out, .
|
|
, out . . out. HasComFactor () . -, ( 1) , true, , false. -,. out , .
// out. using System; class Num {
/* , v . , * out. */ public bool HasComFactor(int x, int y,
out int least, out int greatest) {
Int i;
int max = x < ? x: y; bool first = true;
least = 1; greatest = 1;
// . for(i=2; i <= max/2 + 1; i++) {
if(((y%i)==0) & ((x%i)==0)) {
if (first) { least = i; first = false;
}
greatest = i;
}
}
if(least!= 1) return true; else return false;
}
}
<
class DemoOut {
static void Main() {
Num ob = new Num(); int lcf, gcf;
if(ob.HasComFactor(231, 105, out lcf, out gcf)) {
Console.WriteLine(" " +
" 231 105 " + lcf);
Console.WriteLine(" " +
" 231 105 " + gcf);
}
Else
Console.WriteLine(" 35 49 .");
if(ob.HasComFactor(35, 51, out lcf, out gcf)) {
Console.WriteLine(" " +
" 35 51 " + lcf);
Console.WriteLine(" " +
" 35 51 " + gcf);
}
Else
Console.WriteLine(" 35 51 .");
}
}
, lcf gcf Main () HasComFactor (). HasComFactor () ref, out, . true false, , . , out . .