I am trying to find a perfect number between two given numbers for example 1 and 50. Unfortunately my code prints 1 and 24 as perfect numbers.
Can someone please correct this code and explain what they have done?
I am new to coding so please don't tell me about lists and stuff, I am here to seek your help to know where I am going wrong and how I can improve it. I shall be grateful to you if you will correct this code.
class Program
{
static void Main(string[] args)
{
int n2 = int.Parse(Console.ReadLine());
int n3 = int.Parse(Console.ReadLine());
//int sum;
for (int i = n2; i < n3; i++)
{
int sum = 0;
for (int j = 1; j <= i; j++)
{
if (i % j == 0 )
sum = sum + j;
//Console.WriteLine(j);
if (sum == i )
{
Console.WriteLine("the sum is " + i);
}
}
}
Console.ReadLine();
}
}