Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Perfect-numbers/C-sharp/perfect-numbers-1.cs
Normal file
24
Task/Perfect-numbers/C-sharp/perfect-numbers-1.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Perfect numbers from 1 to 33550337:");
|
||||
|
||||
for (int x = 0; x < 33550337; x++)
|
||||
{
|
||||
if (IsPerfect(x))
|
||||
Console.WriteLine(x + " is perfect.");
|
||||
}
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
static bool IsPerfect(int num)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 1; i < num; i++)
|
||||
{
|
||||
if (num % i == 0)
|
||||
sum += i;
|
||||
}
|
||||
|
||||
return sum == num ;
|
||||
}
|
||||
17
Task/Perfect-numbers/C-sharp/perfect-numbers-2.cs
Normal file
17
Task/Perfect-numbers/C-sharp/perfect-numbers-2.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Perfect numbers from 1 to 33550337:");
|
||||
|
||||
for (int x = 0; x < 33550337; x++)
|
||||
{
|
||||
if (IsPerfect(x))
|
||||
Console.WriteLine(x + " is perfect.");
|
||||
}
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
static bool IsPerfect(int num)
|
||||
{
|
||||
return Enumerable.Range(1, num - 1).Sum(n => num % n == 0 ? n : 0 ) == num;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue