How to print Perfect no in C#...

Shubham
Posted by Shubham under C# category on | Points: 40 | Views : 2453
So what is perfect no????
frndzzzz, Perfect is whose multiplication and add gives same result.
like: 1*2*3=6, 1+2+3=6
=================================================================================================================
using System;
class perfect
{
public static void Main()
{
int num = Convert.ToInt32(Console.ReadLine());
int sum = 0;
for (int i = 1; i < num; i++)
{
sum = 0;
{
for (int j = 1; j < i; j++)

if (i % j == 0)
{
sum = sum + j;
}
}

if (sum == i)
{
Console.WriteLine("The perfect number is:"+ i );
}


}
Console.ReadLine();
}
}

Comments or Responses

Posted by: T.Saravanan on: 2/21/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Kindly post your code inside the code tag.

Login to post response