By | 24.03.2017

# C Program to find number is perfect or not using recursion

Write a C Program to find whether number is perfect or not using recursion. Here’s simple Program to find check whether entered number is perfect or not using recursion in C Programming Language.

## Perfect number

A perfect number is a positive number that equals the sum of its divisors, excluding itself. This is also known as its aliquot sum. At this time, it is unknown how many perfect numbers truly exist in our number system.

While we have discovered 48 perfect numbers, the fact that there are an infinite number of prime numbers leads us to believe that there could be an infinite number of perfect numbers.

Perfect number are positive integers n such that

where s(n) is the restricted divisor function (i.e., the sum of proper divisors of n), or equivalently

where is the divisor function (i.e., the sum of divisors of n including n itself). For example, the first few perfect numbers are 6, 28, 496, 8128, … (OEIS A000396), since

etc.

The nth perfect number is implemented in the Wolfram Language as PerfectNumber[n] and checking to see if k is a perfect number as PerfectNumberQ[k].

The first few perfect number Pn are summarized in the following table together with their corresponding indices (see below).

 1 2 6 2 3 28 3 5 496 4 7 8128 5 13 33550336 6 17 8589869056 7 19 137438691328 8 31 2305843008139952128

Below is the source code for C Program to find whether number is perfect or not using recursion which is successfully compiled and run on Windows System to produce desired output as shown below :

### SOURCE CODE : :

```/*  C Program to find whether number is perfect or not using recursion */

#include<stdio.h>
int sumdiv(int num, int x);

int main()
{
int num;
printf("Enter a number :");
scanf("%d",&num);
if(sumdiv(num, num/2) == num)
printf("\nPerfect Number\n");
else
printf("\nNot Perfect Number\n");
}

sumdiv(int num, int x)
{
if(x==1)
return 1;
if(num%x==0)/*if x is a proper divisor*/
return x + sumdiv(num,x-1);
else
return sumdiv(num,x-1);
}```

### OUTPUT : :

```*************** OUTPUT **************

**************** FIRST RUN : ********

Enter a number :200

Not Perfect Number

**************** SECOND RUN : ********

Enter a number :6

Perfect Number```

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.

Article Rating
Category: C Programming Recursion Programs Tags:

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of

1 Comment
Inline Feedbacks