two left
This commit is contained in:
44
labs/lab4_done/Utils/Utils.cs
Normal file
44
labs/lab4_done/Utils/Utils.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
class Utils
|
||||
{
|
||||
public static int Greater(int a, int b)
|
||||
{
|
||||
if (a > b)
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
}
|
||||
|
||||
public static void Swap(ref int a, ref int b)
|
||||
{
|
||||
int temp = a;
|
||||
a = b;
|
||||
b = temp;
|
||||
}
|
||||
|
||||
public static bool Factorial(int n, out int answer)
|
||||
{
|
||||
int k;
|
||||
int f = 1;
|
||||
bool ok = true;
|
||||
|
||||
try
|
||||
{
|
||||
checked
|
||||
{
|
||||
for (k = 2; k <= n; ++k)
|
||||
{
|
||||
f = f * k;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
f = 0;
|
||||
ok = false;
|
||||
}
|
||||
|
||||
answer = f;
|
||||
return ok;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user