// Perfect Number
/*
A perfect number program in c is a number, whose sum is equal to its positive divisor but excludes the number itself
for example
factors of 6 = 1,2,3
1 + 2 + 3 = 6
therefore is a perfect number
*/
# include <stdio.h>
int main()
{
int n,i=1,sum=0;
printf("Enter any integer value : ");
scanf("%d",&n);
while(i<n)
{
if(n%i==0)
{
sum = sum+i;
}
i++;
}
if(sum==n)
{
printf("Perfect Number");
}
else
{
printf("not a Perfect Number");
}
return 0;
}
// Perfect Number Series
#include <stdio.h>
int main()
{
int i, j,sum=0;
printf("Perfect Numbers from 1 to 500 are\n");
for(i=1; i<=500; i++)
{
for(j=1; j<i; j++)
{
if(i % j == 0)
{
sum = sum + j;
}
}
if(sum == i)
{
printf("%d ", i);
}
sum=0;
}
return 0;
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.