Program to delete duplicates from a link list

program to check an Abundant number

Here in this article we will write program to check that number is abundant or not . So for this first we have to know what is abundant number.

What is an Abundant number: –

A number is said to be Abundant number if sum of it’s all divisors except it is greater than the number itself.

for Example: –

divisors of 12 are 1 , 2 , 3 , 4 , 6 . and sum of all is 16 which is greater than 12 so 12 is an abundant number .

program to check an Abundant number:-

C++ Code:- 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,sum_d=0;
    cout<<"Enter a number\n";
    cin>>n;
    
    // finding sum of divisors
    for(int i=1;i<n;i++)
    {
        if(n%i==0)
         sum_d+=i;
         
    }
    
    //  checking abundant
    if(sum_d>n)
      cout<<n<<" is an abundant number"<<endl;
    else
      cout<<n<<" is not an abundant number"<<endl;
     return 0;
}

Output:- 

Enter a number
18
18 is an abundant number

python code:-

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

output:-

12
12 is an Abundant number

 

Also check this:-

codechef problems:-

Wipro :-

Infytq :-

Key Points;-

Hackerrank:-

C-tutorial:-

See more:-

Leave a Reply

Your email address will not be published.