Programming Examples

C program to check whether the given number is Perfect Number or not


Write a program to check whether the given number is Perfect Number or not

Perfect Number :- Perfect number, a positive integer equal to the sum of its proper divisors. The smallest Perfect number is 6, which is the sum of 1, 2 and 3.

For Example:-

Input = 28

Output = 28 is the Perfect Number.

So as we can see that the divisor of 28 is 1, 2, 4, 7, 14, so the sum of all the divisors is 28 (1 + 2 + 4 + 7 + 14 = 28). Therefore, 28 is the Perfect number.

Solution

#include <stdio.h>
int main()
{
	int num,i;
	int sum;
	printf("Enter any Integer Number");
	scanf("%d",&num);
	sum=0;
	for(i=1; i< num;i++)
	{
		if(num%i==0)
			sum+=i;
	}
	if(sum==num)
		printf("%d is a perfect number.",num);
	else
		printf("%d is not a perfect number.",num);
	return 0;
}
Output

Enter any Number 28

28 is a perfect number.

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz