C Foundation

What is C? C Compiler Installation C Extensions C Compiler C Interpreter C Program Structure

C Basics

C Keywords C Data Types C Identifiers C Variables C Constant C Escape Sequences C Constant and Volatile C Typecast


What is Operator C Comma Operator C Arithmetic Operators C Relational Operators C Logical Operators C Bitwise Operators C Conditional Operators C : : Operator C Operator Priority

Basic IO's

Basic IO's C Formatted Functions C Unformatted Functions C Common Functions

Control Statements

What is Control Statement C if Statement C if else Statement C Nested if Statement C Else if Statement C Break Statement C Continue Statement C Switch Statement C Goto Statement


What is Control Loop C for Loop C Nested for Loop C while Loop C Nested while Loop C do while Loop C Nested do while loop


What is Function C User Defined Functions C Recursion C Passing Parameters


Scope C Local Scope C Global Scope

Storage Classes

What is Storage Class C Auto C Extern C Static C Register


What is Array C One Dimensional Array C Two Dimensional Array C Multi Dimensional Array C Arrays Of Strings


What is String C String Functions


What is Pointer C Pointers Arithmetic C Pointer to Pointer C Pointers and Arrays C Pointers and Strings C Pointer to Functions Void Pointers Null Pointers C Null and Void Pointer


What is Structure C Struct within Struct C Array within Structure C Pointer to Structure C Structure and Function C Enum C Bitfield Structure C Type def


What is Union


What is File C read a file C write a file C File Handling C Error Handling C Low Level Disk I/O C Other file functions

Memory Allocation

What is Memory Allocation C Malloc() C Calloc() C Free() C Realloc() C Coreleft()

C Reference

All ASCII Code Basic C Questions

C Interview

C Interview Sets All Star Patterns All Number Patterns All Alphabet Patterns All Series Patterns
The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

Perfect Number

What is a Perfect number?

A perfect number is defined to be one which is equal to the sum of all its divisible number. For example let us consider a number 6, the numbers which are all divisible by 6 are 1, 2, 3. Then 1 + 2 + 3 = 6 . Thus 6 is a perfect number.

perfect number

Perfect Number - Examples

Some of the following perfect numbers are

Number Explanation
6 1 + 2 + 3
28 1 + 2 + 4 + 7 + 14
496. 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248
8128 1 + 2 + 4 + 8 + 16 + 32 + 64 + 127 + 254 + 508 + 1016 + 2032 + 4064

C Program - To Find a Perfect Number

Let us write a c program to find whether a user entered number is a perfect number or not.

#include <stdio.h>
int main()
int a, b, num;
printf("Enter a number : ");
a = 1;
b = 0;
while(num > a)
if(num % a == 0)
b = b + a;
if(b == num)
printf("\n%d is a perfect number", a);
printf("\n%d is not a perfect number", a);
return 0;
Enter a number : 28
28 is a perfect number


while loop is used for iterating a value from 1 to one number less than user entered number. If the numbers from 1 is divisible by user entered number, then the numbers are added in a dummy variable b. finally we check whether b == user entered number. If so we will declare as a perfect number else it will be declared as not a perfect number.

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.


We to update you