Perfect Number in C

Perfect Number in C

Here you will get a program for the perfect number in C.

A perfect number is a positive number which is equivalent to the entirety of every one of its divisors barring itself.

For instance:

28 is a perfect number as 1 + 2 + 4 + 7 + 14 = 28.

15 isn’t perfect number as 1 + 3 + 5 isn’t equivalent to 15.

Underneath I have shared a program to check whether a number is a perfect number or not.

Program

#include<stdio.h>
 
int main(){
	int num,j,s=0;
	printf("Enter a number:");
	scanf("%d",&num);
	
	for(j=1;j<num;++j){
		if(num%j==0){
			s=s+j;
		}
	}
 
	if(s==num){
		printf("Perfect Number");
	}	
	else{
		printf("Not perfect number");
	}
	
	return 0;
}

Output

DURGESH

I Love python, so I like machine learning a Lot and on the other hand, I like building apps and fun games I post blogs on my website for Tech enthusiast to learn and Share Information With The World.

Leave a Reply

Your email address will not be published. Required fields are marked *

four × four =

Recent Content