Java/PHP/GitLab Fan, Passionate Developer and Loves Teaching

0%

Program to Find Perfect Number's Upto 1000

Summary

Perfect Number is a positive number that is equal to the sum of its proper divisors.

Example

6 is a perfect number since its divisors are 1,2,3 and 1 + 2 + 3 = 6.

Screenshot

Perfect Number Output

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;

namespace TestApplication
{
class PerfectNumber
{
public static void Main()
{
int numbers = 1000;
int sum;
for(int i = 1;i <= numbers; i++)
{
sum = 0;
for (int j = 1; j < i; j++)
{
if (i % j == 0)
{
sum = sum + j;
}
}
if (i == sum)
{
Console.WriteLine(i);
}
}
Console.ReadLine();
}
}
}