using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int l, h, d, s;
Console.Write("\n Enter the low range : ");
l = int.Parse(Console.ReadLine());
Console.Write("\n Enter the high range : ");
h = int.Parse(Console.ReadLine());
Console.Write("\n The perfect numbers are : ");
while (l <= h)
{
s = 0;
d = 1;
while (d < l)
{
if (l % d == 0)
{
s = s + d;
d = d + 1;
}
else
d = d + 1;
}
if (l == s)
Console.Write(" " + l);
l++;
}
Console.ReadLine();
}
}
}
Output

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int l, h, d, s;
Console.Write("\n Enter the low range : ");
l = int.Parse(Console.ReadLine());
Console.Write("\n Enter the high range : ");
h = int.Parse(Console.ReadLine());
Console.Write("\n The perfect numbers are : ");
while (l <= h)
{
s = 0;
d = 1;
while (d < l)
{
if (l % d == 0)
{
s = s + d;
d = d + 1;
}
else
d = d + 1;
}
if (l == s)
Console.Write(" " + l);
l++;
}
Console.ReadLine();
}
}
}
Output
No comments:
Post a Comment