C program to check whether the input number is a perfect number or not using function.
Perfect Number:
The Sum of all positive divisors except that number is equal to that number is known as the perfect number
Example:
The smallest perfect number is 6.
Divisor of 6 are 1,2,3. The Sum of divisors is
1+2+3=6
#include<stdio.h>
void per(int n)
{
int i=1,s=0;
while(i<n)
{
if(n%i==0)
s=s+i;
i++;
}
if(s==n)
printf("\nInput number is a Perfect Number:%d",i);
else
printf("\n Input number is NOT a Perfect Number:%d",i);
}
int main()
{
int num;
printf("Enter any Number : ");
scanf("%d",&num);
per(num);
return 0;
}
No comments:
Post a Comment