Menu Close

Given number a perfect number or not…[cprogm]FTC

Darsh seemingly down-to-earth guy. Dash has a Brother Nathan. Nathan leads a life of a computer hacker by day and a thief by night.  One day, Nathan tries to break the door digital lock of Darsh’s room. 

Darsh who wants to prevent it thinks to give Passcode for security.

But it only accepts a perfect number as input. Can you help him to make a program for checking the given number is the perfect number or not…

Explanation

For example, 6 is a positive number that is completely divisible by 1, 2, and 3.

We know that the number is also divisible by itself but we will include it in the addition of divisors. When we add these divisors (1 + 2 + 3 = 6), it produces 6, which is equal to the number that we have considered. So, we can say that 6 is a perfect number.

Input:
Get a integer input “num”

Output: 
The given number is a perfect number or not a perfect number.
#include <stdio.h>
int perfect(int number);
int main()
{
  int a;
  scanf("%d",&a);
  if(perfect(a)==a)
  printf("Perfect Number");
  else
  printf("Not a Perfect Number");
  return 0;
}
int perfect(int numbr)
{
  int i,sum=0;
  for(i=1;i<=numbr/2;i++)
  {if(numbr%i==0){
      sum+=i;}
  }
return sum;
}

INPUT_1:
6

OUTPUT:
Perfect Number


INPUT_2:
496

OUTPUT:
Perfect Number


INPUT_3:
28
OUTPUT:
Perfect Number


 


INPUT_4:
10

OUTPUT:
Not a Perfect Number


INPUT_5:
30

OUTPUT:
Not a Perfect Number


ILLUSTRATION

Executed using gcc