# Program to check that number is perfect number or not

**Program to check that number is perfect number or not**

Given a number , write a Program to check that number is perfect number or not.

**Sample input:- **

6

**Sample output:-**

6 is a perfect number

## What is perfect number: –

A number is said to be perfect if sum of it’s all divisors excepts it is equals to the number itself.

For example : – 6 is a perfect number because divisors of 6 are 1 , 2 ,3 and sum of all these are 6 which is equal to the number 6 .

**Code :-**

**C language:-**

#include<stdio.h> int main() { int n,sumd=0; printf("Enter a number\n"); scanf("%d",&n); // logic for finding the divisors and their sum for(int i=1;i<n;i++) { if(n%i==0) sumd+=i; } if(sumd==n) printf("%d is a perfect number",n); else printf("%d is not a perfect number",n); return 0; }

**C++ code:-**

#include<bits/stdc++.h> using namespace std; int main() { int n,sumd=0; cout<<"Enter a number\n"; cin>>n; // finding diviors and their sum for(int i=1;i<n;i++) { if(n%i==0) sumd+=i; } // if sum equal to number if(sumd==n) cout<<n<<" is a perfect number"<<endl; else cout<<n<<" is not a perfect number"<<endl; return 0; }

**Output:- **

Enter a number 6 6 is a perfect number

## python code:-

n=int(input()) sum=0 for i in range(1,n): if n%i==0: sum=sum+i if n==sum: print(n,"is a perfect number ") else: print(n,"is not a perfect number")

output:-

28 28 is a perfect number

**Also check this:-**

__codechef problems:-__- Primary test
- Sum or difference
- point and line

__Wipro :-__

- Update the booking ID | Wipro previous year question paper solution
- Pages in PDF
- Find the location id
- Find the odd digits
- Find the Product ID

__Infytq :-__

__Key Points;-__

__Hackerrank:-__

- Python : missing characters : hackerrank solution
- Python : string transformation | Hackerrank solution
- Active Traders certification test problem | Hackerrank Solution
- Usernames changes certification test problem | Hackerrank Solution
- string Representation of objects certification test hackerrank solution
- Average Function | hackerrank certification problem solution

__C-tutorial:-__

- Micros in C
- Pointer in c
- Function declaration
- Types of user define function
- return type of function
- 2D array

__See more:-__

- c program to convert specified days into years weeks and days

- Print Reverse Hollow Pyramid
- Update the booking ID | Wipro previous year question paper
- Pages in PDF | Wipro previous year question paper
- Sparse Matrix in data structure
- Find the location ID | Wipro previous year Coding question
- find the odd digits | Wipro Coding question
- Find the product id | Wipro Coding question
- Difference between static and dynamic memory allocation
- What is asymptotic Notation