+ 2
Program to determine if a no. Is a perfect no. Or not
hi guys this weekend I was free so I wanted to create a program in Java to determine whether a no. is perfect or not but I can't make that for this I have created a program to take out the factors of the input No. u can take the help of that and in case u don't know what is a perfect no.then it is a no. whose sum of factors is equal to the no. like 6=1x2x3 and 6=1+2+3 any answer will be appreciated
2 ответов
+ 5
int number, factor = 0;
// Code to get number
for(int x = 1; x < number; x++) {
if(number % x == 0) {
factor += x;
}
}
if(factor == number) {
System.out.println("Perfect number!");
} else {
System.out.println("Not perfect.");
}
+ 1
thanks