This C# Program Checks Whether the Entered Number is a Perfect Number or Not. A perfect number is a positive integer that is equal to the sum of its proper divisors.
class Program
{
static void Main(string[] args)
{
int number, sum = 0, n;
Console.Write("enter the
Number");
number = int.Parse(Console.ReadLine());
n = number;
for (int i = 1; i < number; i++)
{
if (number % i == 0)
{
sum = sum + i;
}
}
if (sum == n)
{
Console.WriteLine("\n Entered
number is a perfect number"); //6
Console.ReadLine();
}
else
{
Console.WriteLine("\n Entered
number is not a perfect number");
Console.ReadLine();
}
}
}
}
0 comments:
Post a Comment