class PerfectSum
{
public static void main(String[] args)
{
int i, j, end, sum,sum1=0;
System.out.println("Sum Of All Perfect numbers between 1 to 1000\n");
for(i=1; i<=1000; i++)
{
sum = 0;
for(j=1; j<i; j++)
{
if(i % j == 0)
{
sum += j;
}
}
if(sum == i)
{
System.out.println(" "+i);
sum1=sum1+i;
}
}
System.out.print(" Sum Of All Perfect No. is: "+sum1);
}
}
{
public static void main(String[] args)
{
int i, j, end, sum,sum1=0;
System.out.println("Sum Of All Perfect numbers between 1 to 1000\n");
for(i=1; i<=1000; i++)
{
sum = 0;
for(j=1; j<i; j++)
{
if(i % j == 0)
{
sum += j;
}
}
if(sum == i)
{
System.out.println(" "+i);
sum1=sum1+i;
}
}
System.out.print(" Sum Of All Perfect No. is: "+sum1);
}
}
No comments:
Post a Comment