Perfect number : is a positive integers which is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself
6 has factors 1,2,3 and 6(number itself)
(or)
Perfect number : is a positive integers which is equal to the sum of its proper positive factors, that is, the sum of its positive factors excluding the number itself
For example
import java.util.*;
class perfect{ public static void main(String args[]) { int n,sum=0; System.out.println("Enter a number: "); Scanner obj=new Scanner(System.in); n=obj.nextInt(); for(int i=1;i<n;i++) { if(n%i==0) sum+=i; } if(n==sum) System.out.println(n+" is a Perfect number"); else System.out.println(n+" is not Perfect number"); }
}


No comments:
Post a Comment