3. A. CHECK WHETHER THE GIVEN NUMBER IS PERFECT
NUMBER
POSITIVE DIVISORS, THAT IS, THE SUM OF ITS POSITIVE
DIVISORS EXCLUDING THE NUMBER ITSELF.
EXAMPLE - THE FIRST PERFECT NUMBER IS 6, BECAUSE 1, 2, AND
3 ARE ITS PROPER POSITIVE DIVISORS, AND 1 + 2 + 3 = 6
SOURCE CODE:
#include<stdio.h>
void main()
{
int n,i=1,sum=0;
printf("\nEnter a number: ");
scanf("%d",&n);
while(i<n){
if(n%i==0)
sum+=i;
i++;
}
if(sum==n)
printf("\n%d is a Perfect Number",i);
else
printf("\n%d is Non Perfect Number",i);
}
0 comments:
Post a Comment