PROGRAM 5 : ENTER THE NUMBER OF ABUNDANT NUMBERS TO BE FOUND.
(Abundant number is number whose sum of all factors of that number(excluding number itself)is greater the number itself.
Example: 12 , 30 , 36 , 42)
PROGRAM:
import java.util.Scanner;
public class abundunt_number
{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("enter the number of abundunt numbers to be found:");
int n = sc.nextInt();
int counter = 0;
for(int i = 10; counter<n ; i++){
if (isabund(i)){
System.out.print(i + " " );
counter++;
}
}
}
public static boolean isabund(int a){
int lim = a/2;
int sum = 0;
for(int i = 1 ; i<=lim ; i++){
if(a%i==0){
sum+=i;
}
}
if(sum > a){
return true;
}
else{
return false;
}
}
}
No comments:
Post a Comment