# Program to Determine Whether a Given Number is a Deficient Number

Program to determine whether a given number is a Deficient number on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph, pattern, string etc.

## Program to determine whether a given number is a Deficient number

The deficient number can be defined as the number for which the sum of the proper divisors is lesser than the number itself.

For example, the number 21 with its proper divisors (1, 3 and 7) has sum (11) lesser than itself.

### Algorithm

MAIN

• STEP 1: START
• STEP2: Enter n
• STEP 3: if Def(n) is true then
print "yes"
else
print "no"
• STEP 4: END

Def(n)

• STEP 1: START
• STEP 2: set i = divsum(n)
• STEP 3: if i <2n
then return true
else
return false
• STEP 3: END

divsum(n)

• STEP 1: START
• STEP 2: SET sum= 0
• STEP 3: REPEAT STEP 4 UNTIL i<=?n
• STEP 4: if (n% i==0)
then
if(n/i==i)
sum=sum+i
else
sum=sum+i
sum=sum+ (n/i)
• STEP 5: RETURN sum
• STEP 6: END

### Java Program

```import java.util.*;
class Deficient
{
static int divsum(int n)
{
int sum = 0;
for (int i = 1; i <= (Math.sqrt(n)); i++) {
if (n % i == 0) {

if (n / i == i) {
sum = sum + i;
}
else
{
sum = sum + i;
sum = sum + (n / i);
}
}
}

return sum;
}

static boolean isDef(int n)
{
return (divsum(n) < (2 * n));
}

public static void main(String args[])
{
System.out.println("Enter the number?");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (isDef(n))
System.out.println("The number is deficient.");
else
System.out.println("The number is not deficient");
}
}
```

Output:

```Enter the number? 23
The number is deficient.
```

### C Program

```#include<stdio.h>
#include<math.h>
int divsum(int n)
{
int i;
int sum = 0;
for (int i = 1; i <= (sqrt(n)); i++) {
if (n % i == 0) {
if (n / i == i) {
sum = sum + i;
}
else
{
sum = sum + i;
sum = sum + (n / i);
}
}
}
return sum;
}

int isDef(int n)
{
return (divsum(n) < (2 * n));
}

void main()
{
char var[100];
int n;
printf("Enter the number?");
scanf("%d",&n);
if(isDef(n) == 0)
printf("The number is not deficient.");
else

}
```

Output:

```Enter the number? 21
The number is deficient.
```

### Python Program

```import math
def divsum(n) :
sum = 0
i = 1
while i<= math.sqrt(n) :
if (n % i == 0) :

if (n / i == i) :
sum = sum + i
else :
sum = sum + i;
sum = sum + (n / i)
i = i + 1
return sum
def isDef(n) :

return (divsum(n) < (2 * n))

n = int(input("Enter the number?"))
if ( isDef(n) ):
print("The number is deficient.")
else :
print("The number is not deficient.")
```

Output:

```Enter the number? 45
The number is deficient.
```

### C# Program

```using System;
class Deficient{
static int divsum(int n)
{
int sum = 0;

for (int i = 1; i <= (Math.Sqrt(n)); i++) {
if (n % i == 0) {
if (n / i == i) {
sum = sum + i;
}
else               {
sum = sum + i;
sum = sum + (n / i);
}
}
}

return sum;
}

static bool isDef(int n)
{
return (divsum(n) < (2 * n));
}

public static void Main()
{
Console.WriteLine("Enter the number?");
int n = Convert.ToInt32(Console.ReadLine());
if(isDef(n))
{
Console.WriteLine("The number is deficient.");
}
else
{
Console.WriteLine("The number is not deficient.");
}
}
}
```

Output:

```Enter the number? 45
The number is deficient.
```

### PHP Program

```<?php
function divsum(\$n)
{
\$sum = 0;
for (\$i = 1; \$i <= sqrt(\$n); \$i++)
{
if (\$n % \$i==0)
{
if (\$n / \$i == \$i)
{
\$sum = \$sum + \$i;
}
else
{
\$sum = \$sum + \$i;
\$sum = \$sum + (\$n / \$i);
}
}
}
return \$sum;
}

function isDef(\$n)
{
return (divsum(\$n) < (2 * \$n));
}
echo "Enter the number?";
\$n=readline();
\$ds = isDef(n) ?   "The number is defecient." :  "The number is not deficient.";
echo(\$ds);
?>
```

Output:

```Enter the number? 45
The number is deficient.
```
Next Topic#

### Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf