In: Computer Science
In C# Please Write an application named Perfect that displays every perfect number from 1 through 10,000. A number is perfect if it equals the sum of all the smaller positive integers that divide evenly into it. For example, 6 is perfect because 1, 2, and 3 divide evenly into it and their sum is 6.
Starting code.
using static System.Console;
class Perfect
{
static void Main()
{
// Write your main here.
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perfect
{
class Program
{
static void Main(string[] args)
{
int n, i, sum;
int mn, mx;
Console.Write("\n\n");
Console.Write("Find perfect numbers within a given number of
range:\n");
Console.Write("------------------------------------------------------");
Console.Write("\n\n");
Console.Write("Starting number : ");
mn = Convert.ToInt32(Console.ReadLine());
Console.Write("Ending number : ");
mx = Convert.ToInt32(Console.ReadLine());
Console.Write("The Perfect numbers in range : ");
for (n = mn; n <= mx; n++)
{
i = 1;
sum = 0;
while (i < n)
{
if (n % i == 0)
sum = sum + i;
i++;
}
if (sum == n)
Console.Write("{0} ", n);
}
Console.Write("\n");
Console.ReadLine();
}
}
}
if you have any doubt then please ask me without any hesitation in
the comment section below , if you like my answer then please
thumbs up for the answer , before giving thumbs down please discuss
the question it may possible that we may understand the question
different way and we can edit and change the answers if you argue,
thanks :)