C program to find the perfect number using for loop| Perfect number in C |E-studyblog

In this Article, you will learn  C program to find the perfect number using for loop.To find the perfect number, first of all, we have to take out all divisors of that given number, then their sum, if  sum is equal to that given number then it is called to be Perfect number.

                 
C program to find the perfect number using for loop|perfect number in c|E-studyblog
C program to find the perfect number using for loop|perfect number in C |E-studyblog

Perfect number :

A Perfect number is  a positive number which is equal to the sum of its proper divisors.

For Example: 6 is a perfect number since it is divisible by 1,2 and 3.

Others Perfect numbers are :28,496 Etc


C program to find the perfect number using for loop:


 /* C program to find the perfect number using for loop */
 
#include <stdio.h> 
int main(){
	int i,n,s=0;
	printf("\nEnter an Integer:");
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{
		if(n%i==0)
		s=s+i;
		
	}
	if(s==n)
	
	printf("%d is a Perfect Number:",n); 
	  
    else   
    printf("%d is not the Perfect Number:",n);   
    
    return 0;
}


    


Output:

C program to find the perfect number using for loop| Perfect number in C |E-studyblog

C program to find the perfect number using for loop| Perfect number in C |E-studyblog





I hope you have read our Article " C Program to find perfect of the number using for loop"and  you have collected lots of information from there.If you like the post,then please comment and share among your friends and family. you can write your opinion about my post in the comment box. 


Thank you!


No comments:

Post a Comment

If you have any queries ,please let us know

C Program to Check whether the number is Even or Odd|how to find odd and even numbers in c programming|E-studyblog

I n this Article, you will learn how to   Check  whether the number is  Even or odd. We have shared the source code of odd and even number i...