| | |
perfect numbers . . !
![]() |
•
•
Join Date: Nov 2009
Posts: 24
Reputation:
Solved Threads: 0
Can any one help me with this exercise . . !
I did not understnd it . ?
A number is called a proper divisor of N if M < N and M divides N. A positive integer is called perfect if it is the sum of its positive proper divisors. For example, the positive proper divisors of 28 are 1, 2, 4, 7, and 14 and 1+2+4+7+14=28. Therefore, 28 is perfect. Write a program to display the first 4 perfect integer ..
I did not understnd it . ?
A number is called a proper divisor of N if M < N and M divides N. A positive integer is called perfect if it is the sum of its positive proper divisors. For example, the positive proper divisors of 28 are 1, 2, 4, 7, and 14 and 1+2+4+7+14=28. Therefore, 28 is perfect. Write a program to display the first 4 perfect integer ..
Last edited by alreem; Nov 20th, 2009 at 5:26 pm.
•
•
Join Date: May 2008
Posts: 59
Reputation:
Solved Threads: 1
0
#2 Nov 20th, 2009
•
•
•
•
Can any one help me with this exercise . . !
I did not understnd it . ?
A number is called a proper divisor of N if M < N and M divides N. A positive integer is called perfect if it is the sum of its positive proper divisors. For example, the positive proper divisors of 28 are 1, 2, 4, 7, and 14 and 1+2+4+7+14=28. Therefore, 28 is perfect. Write a program to display the first 4 perfect integer ..
It gives a good example.
I think the first perfect integer is 6 because positive proper divisors are 1 2 3 and 1+2+3 = 6.
12 is not perfect cause 1+2+3+4+6 = 16 > 12
I even calculated the numbers from 1 to 20 in my mind, and found none.
You got it?
•
•
Join Date: Feb 2009
Posts: 34
Reputation:
Solved Threads: 0
0
#3 Nov 20th, 2009
I think this is a homework problem.....I did the coding and the first 4 perfect numbers are:
The perfect number is 6
The perfect number is 28
The perfect number is 496
The perfect number is 8128
Anyways, I will not give away the solution and rob you of your valuable education, however I will give the pseudo code......hope you can do the rest.....
The perfect number is 6
The perfect number is 28
The perfect number is 496
The perfect number is 8128
Anyways, I will not give away the solution and rob you of your valuable education, however I will give the pseudo code......hope you can do the rest.....
Java Syntax (Toggle Plain Text)
class name { public static void main(String[] args) { initialize a count variable to 0 this will help you to count to first 4 perfect numbers use for loop to check first 10000 numbers from which to get the first 4 perfect numbers starting from i=1 { initialize sum variable use for loop from variable j=1 to check till i { check divisibility find sum of j's if i is divisble by j } use if statement to check for perfect number and if count is less than 5 { print the perfect number and increase count by one } } } }
•
•
Join Date: Nov 2009
Posts: 24
Reputation:
Solved Threads: 0
0
#5 Nov 21st, 2009
Java Syntax (Toggle Plain Text)
package perfectnumbers; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int num,count,sum; System.out.printf(" Enter ur number: "); num = read.nextInt(); count=0; for( int m=1 ; m <10000; m++) { sum=0; for ( int n=1; n<m; m++ ) { if ( m %n == 0 ) sum = sum + n; else; } if ((num / m) && ( count < 5)) System.out.println (" The perfect number is: "); else; } count ++; } } } }
Last edited by alreem; Nov 21st, 2009 at 6:43 am.
•
•
Join Date: Feb 2009
Posts: 34
Reputation:
Solved Threads: 0
0
#7 Nov 21st, 2009
Java Syntax (Toggle Plain Text)
Scanner read = new Scanner(System.in); System.out.printf(" Enter ur number: "); num = read.nextInt();
There is no need to take input from the user. You are checking for perfect numbers from 1 to 10000.
also to check for perfect number you should use the condition
sum==m (i.e 1+2+3 = = 6)
•
•
Join Date: Nov 2009
Posts: 24
Reputation:
Solved Threads: 0
0
#8 Nov 21st, 2009
Java Syntax (Toggle Plain Text)
count=0; for( int m=1 ; m <10000; m++) { sum=0; for ( int n=1; n<m; m++ ) { if ( m %n == 0 ) sum = sum + n; else; } if ((num / m) && ( count < 5)) System.out.println (" The perfect number is: "); else; } count ++; }
like this . . ?
•
•
Join Date: Feb 2009
Posts: 34
Reputation:
Solved Threads: 0
0
#9 Nov 21st, 2009
try something like this
Java Syntax (Toggle Plain Text)
count=0; for( int m=1 ; m <10000; m++) { sum=0; for ( int n=1; n<m; m++ ) { if ( m %n == 0 ) sum = sum + n; else; } if ((sum==m) && ( count < 5)) System.out.println (" The perfect number is: "); else; count ++; } }
![]() |
Similar Threads
- help!!! perfect numbers from 1-1000..and its factors (Java)
- perfect numbers (Python)
- perfect numbers (Python)
- perfect numbers (C)
- Finding Perfect Numbers. "help plz" (C++)
Other Threads in the Java Forum
- Previous Thread: Round-Robin Scheduling Algorithm
- Next Thread: How to build a simple online bookstore
Views: 1051 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for Java
access android api apple applet application arguments array arrays automation binary c++ chat class classes client code combobox compiler component converter coordinates data database db design detection draw eclipse error event exception fast file fractal game givemetehcodez graphics gridlayout gui helpwithhomework html ide image inheritance input integer interface j2me java jni jpanel jtable jtextfield julia linux list loop map method methods mobile netbeans newbie number object objects oracle os pattern phone pixel print problem program programming project read recursion regex remote remove robot scanner screen search server set size sms socket string swing test text threads timer transfer tree windows





