PERFECT NUMBER :
PERFECT NUMBER IS A POSITIVE NUMBER WHOSE SUM OF ALL POSITIVE DIVISORS EXCLUDING THAT NUMBER IS EQUAL TO THAT NUMBER
FOR EXAMPLE : 6 IS A PERFECT NUMBER SINCE DIVISOR OF 6 ARE 1,2,3. SUM OF ITS DIVISORS IS 1+ 2 + 3 = 6
FOR EXAMPLE : 28 IS A PERFECT NUMBER SINCE DIVISOR OF 28 ARE 1,2,4,7,14. SUM OF ITS DIVISORS IS 1+ 2 + 4 + 7 + 14 = 28
FOR EXAMPLE : 496 IS A PERFECT NUMBER
FOR EXAMPLE : 8128 IS A PERFECT NUMBER
PROGRAM:
// program to illustrate perfect number
#include<stdio.h>
void main()
{
int n,i=1,sum=0,temp;
printf("Enter any number:");
scanf("%d",&n);
temp=n;
while (i < n)
{
if( n % i == 0 )
sum =sum + i;
i++;
}
if (sum == temp)
printf("%d is a perfect number",temp);
else
printf("%d is not a perfect number",temp);
}
output:
#include<stdio.h>
void main()
{
int n,i=1,sum=0,temp;
printf("Enter any number:");
scanf("%d",&n);
temp=n;
while (i < n)
{
if( n % i == 0 )
sum =sum + i;
i++;
}
if (sum == temp)
printf("%d is a perfect number",temp);
else
printf("%d is not a perfect number",temp);
}
output:
No comments:
Post a Comment