Write A Program That Will Show Perfect Numbers from 1 to 1000
Note: What is a perfect number?
Perfect numbers are those numbers whose that is sum of its divisors excluding itself.
For example:
1+2+3 = 6
1+2+4+7+14 = 28
#include <stdio.h>
#include <conio.h>
int main()
{
int num,i,sum;
printf("Perfect numbers are: ");
for(num = 1; num <= 1000; num++){
i=1;
sum = 0;
while(i < num)
{
if(num % i == 0)
sum = sum+i;
i++;
}
if(sum==num)
printf("%d ",num);
}
getch();
}
Perfect numbers are those numbers whose that is sum of its divisors excluding itself.
For example:
1+2+3 = 6
1+2+4+7+14 = 28
#include <stdio.h>
#include <conio.h>
int main()
{
int num,i,sum;
printf("Perfect numbers are: ");
for(num = 1; num <= 1000; num++){
i=1;
sum = 0;
while(i < num)
{
if(num % i == 0)
sum = sum+i;
i++;
}
if(sum==num)
printf("%d ",num);
}
getch();
}