# Print Abundant numbers in a given range(1 to n)

### Example:-

18 divisors are 1, 2, 3, 6, 9, 18

sum of divisors=1+2+3+6+9+18=39
18<39
Number < sum of divisors

#### Sample Input/Output:-

Sample Input First: 10 50                 Sample Output First: 12 18 20 24 30 36 40 42 48

Sample Input Second: 650 700        Sample Output Second650 654 660 666 672 678 680                                                                                                     684 690 696 700

#### Data requirement:-

Input Data:- range1, range2

Output Data:-j

Program in C

Here is the source code of the C Program to Find out all Abundant numbers present within a given range.

Code:

#include<stdio.h>
int main()
{
int range1,range2,j,i;
printf("Enter a range:");
scanf("%d %d",&range1,&range2);
printf("Abundant numbers between %d and %d are: ",range1,range2);
for(j=range1;j<=range2;j++)
{
int sum=0;
for(i=1;i<j;i++)
{
if(j%i==0)
{
sum=sum+i;
}
}
if(sum>j)
printf("%d ",j);
}
}

Input/Output:
Enter a range:
10
50
Abundant numbers between 10 and 50 are: 12 18 20 24 30 36 40 42 48

Program in C++

Here is the source code of the C++ Program to print Abundant numbers in a given range.

Code:

#include<iostream>
using namespace std;
int main()
{
int range1,range2;
cout<<"Enter a range:";
cin>>range1>>range2;
cout<<"Abundant numbers between "<<range1<<" and "<<range2<<" are: ";
for(int j=range1;j<=range2;j++)
{
int sum=0;
for(int i=1;i<j;i++)
{
if(j%i==0)
{
sum=sum+i;
}
}

if(sum>j)
cout<<j<<" ";
}
}

Input/Output:
Enter a range:
300
350
Abundant numbers between 300 and 350 are: 300 304 306 308 312 318 320 324 330 336 340 342 348 350

Program in Java

Here is the source code of the Java Program to Find out all Abundant numbers present within a given range.

Code:

import java.util.Scanner;
public class FindAbundantNumbersInRange {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int range1,range2;
System.out.println("Enter a range:");
range1=cs.nextInt();
range2=cs.nextInt();
System.out.println("Abundant numbers between "+range1+" and "+range2+" are: ");
for(int j=range1;j<=range2;j++)
{
int sum=0;
for(int i=1;i<j;i++)
{
if(j%i==0)
{
sum=sum+i;
}
}
if(sum>j)
System.out.print(j+" ");
}
cs.close();
}
}

Input/Output:
Enter a range:
650
700
Abundant numbers between 650 and 700 are:
650 654 660 666 672 678 680 684 690 696 700

Program in Python

Here is the source code of the Python Program to print Abundant numbers in a given range.

Code:

print("Enter a range")
range1=int(input())
range2=int(input())
print("Abundant numbers between ",range1," and ",range2," are: ")
for j in range(range1,range2+1):
sum=0
for i in range(1,j):
if(j%i==0):
sum=sum+i
if sum>j:
print(j,end=" ")

Input/Output:
Enter a range
9000
9050
Abundant numbers between  9000  and  9050  are:
9000 9006 9012 9016 9018 9020 9024 9030 9036 9040 9042 9044 9048