Program:
/* Perfect Number :
If a given number = sum of its divisible expect that number, that number is called Perfect Number
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i, sum=0;
clrscr();
printf("Enter any Number : ");
scanf("%d", &n);
for(i=1; i<=n/2; i++)
{
if(n%i==0)
sum=sum+i;
}
if(n==sum)
printf("Given Number is Perfect Number ");
else
printf("Given Number is Not Perfect Number");
getch();
}
Output:
Ex-1:
Enter any Number : 6
Given Number is Perfect Number
Ex-2:
Enter any Number : 28
Given Number is Perfect Number
Ex-3:
Enter any Number : 24
Given Number is Not Perfect Number
Next Topic :
Previous Topic :
No comments:
Post a Comment