Q:

Program to determine whether a given number is an abundant number

belongs to collection: Number Programs

0

The abundant number can be called as an excessive number and defined as the number for which the sum of its proper divisors is greater than the number itself.

A first abundant number is the integer 12 having the sum (16) of its proper divisors (1, 2, 3, 4, 6) which is greater than itself (12).

Examples: 12, 18, 20, 24, 30, 36

In this program, we have to check whether a given number is an abundant number using the algorithm given below.

Algorithm

MAIN

  • STEP 1: START
  • STEP 2: ENTER n.
  • STEP 3: if CheckAbundant(n) is true
    then PRINT "yes"
    else
    PRINT "no".

CheckAbundant (n)

  • STEP 1: START
  • STEP 2: SET i= GetSum(n)
  • STEP 3: if i>n
    then RETURN true
    else
    RETURN false.

GetSum(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: sum =sum - n
  • STEP 6: RETURN sum

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Java program

import  java.util.*;  
public  class Abundant_number {  
    public static void main(String[] args) {  
        System.out.println("Enter the number?");  
        Scanner sc = new Scanner(System.in);  
        int n = sc.nextInt();  
        Abundant_number  a = new Abundant_number();  
        if(a.checkAbundant(n))  
    {  
        System.out.println("The number is Abundant.");  
    }  
    else   
    {  
        System.out.println("The number is not Abundant.");  
    }  
    }  
public int getSum(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);  
            }  
        }  
    }  
    sum = sum - n;  
    return sum;  
}  
public  boolean checkAbundant(int n)  
{  
    return (getSum(n) > n);  
}}  

 

Output:

Enter the number?
20
The number is Abundant

 

C program

# include <stdio.h>  
# include <string.h>  
# include <stdbool.h>  
# include <math.h>  
int getSum(int n)  
{  
    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);  
            }  
        }  
    }  
    sum = sum - n;  
    return sum;  
}  
bool checkAbundant(int n)  
{  
    return getSum(n) > n;  
}  
int main()  
{  
int n;  
printf("Enter the number?");  
scanf("%d",&n);  
checkAbundant(n)? printf("The number is Abundant.\n") : printf("The number is not Abundant.\n");  
    return 0;  
}  

 

Output:

Enter the number? 34
The number is not Abundant.

 

Python Program:

def is_abundant(n):  
    fctr_sum = sum([fctr for fctr in range(1, n) if n % fctr == 0])  
    return fctr_sum > n  
a = int(input("Enter the number?"));  
if is_abundant(a):  
    print("The number is Abundant.");  
else:  
    print("The number is not Abundant.")  

 

Output:

Enter the number?24
The number is Abundant.

 

C# program

using System;   
public class AbundantNumber {   
public static int getSum(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);   
                }   
            }   
        }   
   
        sum = sum - n;   
        return sum;   
    }   
    static bool Abundant(int n)   
    {   
        return (getSum(n) > n);   
    }   
    
    public static void Main()   
    {   
        Console.WriteLine("Enter the number?");  
                int n = Convert.ToInt32(Console.ReadLine());  
        if(Abundant(n))  
        {  
            Console.WriteLine("The number is Abundant.");  
        }  
        else  
        {  
            Console.WriteLine("The number is not Abundant.");  
        }  
    }   
}  

 

Output:

Enter the number?
67
The number is not Abundant.

 

PHP Program

<?php  
echo "Enter the number?";  
$n=readline();  
$k = abundant($n) ? "The number is Abundant." : "The number is not Abundant.";   
echo($k);   
function value($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);   
            }   
        }   
    }   
    $sum = $sum - $n;   
    return $sum;   
}     
function abundant($n)   
{  
    return (value($n) > $n);   
}   
?>  

 

Output:

Enter the number? 56
The number is Abundant.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Program to determine whether a given number is a t... >>
<< Program to determine whether a given number is a D...