Discussion Forums

New User? Please read instructions!

What is perfect number and write a C program to check given number is perfect number or not  

  RSS

thiyagarajan
Eminent Member
Joined: 2 months  ago
Posts: 26
27/01/2017 9:45 am  

What is perfect number and write a C program to check given number is perfect number or not


ReplyQuote
admin
Eminent Member
Joined: 5 years  ago
Posts: 26
10/02/2017 7:04 am  

What is perfect number?

A number is considered as perfect number when it satisfies the below conditions.

  • It should be a positive number
  • When the sum of it's divisors (excluding that number) are equal to that number

 

Example for perfect numbers:

6, 28, 496, 8128

Description:

1 + 2 + 3 = 6

1 + 2 + 4 + 7 + 14 = 28

 

C program to check given number is perfect number or not:

Please refer below C program to check whether given number is perfect number or not.

 

#include<stdio.h>

int main()

{

     int number, sum=0, i=1;

     printf("Please enter a number to check perfect number\n");

     scanf("%d",&number);

 

     while(i<number)

     {

           if(number%i==0)

           {

               sum=sum+i;

           }

           i++;

     }

      if(sum==number)

           printf("\nEntered number %d is a perfect number",i);

     else

          printf("\nEntered number %d is not a perfect number",i);

     return 0;

}

 

Output:

Please enter a number to check perfect number

28

Entered number 28 is a perfect number

 

Edited: 2 months  ago

ReplyQuote
  
Working

Please Login or Register

Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!