954,178 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

perfect numbers . . !

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 ..

alreem
Newbie Poster
24 posts since Nov 2009
Reputation Points: 10
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 ..

you did not understand?

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?

gangsta1903
Junior Poster
111 posts since May 2008
Reputation Points: 12
Solved Threads: 8
 

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.....

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				
			}
		}
		
	}

}
redmaverick
Light Poster
35 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

I got it ..
I will do it know .. if I can =)

Thanx for yours explanation ..

alreem
Newbie Poster
24 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
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 ++;
    }

}
    }
}
alreem
Newbie Poster
24 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

It's not true . !

alreem
Newbie Poster
24 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
It's not true . !
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)

redmaverick
Light Poster
35 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 
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 . . ?

alreem
Newbie Poster
24 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

try something like this

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 ++;   

  }     

 }
redmaverick
Light Poster
35 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

does not work . . !


it gives me :

the perfect number is:
the perfect number is:
the perfect number is:
the perfect number is:

alreem
Newbie Poster
24 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
int count,sum,m = 0,n = 0;

      count=1;
      while ( count <= 10000 )
      {
          sum=0;
         while (  n <  m )
          {
              if ( m %n == 0 )
                  sum = sum +  n;
              else;
           
       }
          if ((sum==m) && ( count < 5))
              System.out.println (" The perfect number is: %d\n ");
          else;

      count ++;
      }
    }
    }


I do it like this , , but the numbers does not appear . . !

alreem
Newbie Poster
24 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

its basic way how to input proper divisor;;
take a look around;
\

/*
 *Name: federick c, pasco
 *Date: Feb.16, 2011
 *Description: to calculate a proper divisor into an Integers, 
 */
 
 import java.io.*;
 public class ProperDivisor
 {
 	public static void main (String [] args) throws IOException
 	{
 	
 	BufferedReader value  = new BufferedReader (new InputStreamReader(System.in));
 	
 	
 	  String input;
 	  int proper;
 	  //int m;
 	  
 	  
 	do{
 		
 		System.out.print("\n\n=====================================================================");
 		System.out.print("\n\nEnter an integer: ");
 	    proper = Integer.parseInt(value.readLine());
 	    int z=proper-1;
 	    
 	    System.out.print("The proper divisors of " + proper + " are ");
 	    
 	    for (int a=1; a<=z; a++)// loop a= start 1 z=end sa loop
 	    {
 	    	int m=proper%a;// variable 
 	    	if (m==0) // condotion sa int m f mo true ang sa loop i print ang # nga na belong sa for loop
 	    	System.out.print(+ a +",");
 	    
 	    }
 	 	
 	 	System.out.print("\nTry Again? (yes or no):");
		input = value.readLine();
	
 	 	
 	}while(input.equalsIgnoreCase("yes"));
 	
 	System.out.print("\n\n=====================================================================");
 
 	}
 }
milkhey
Newbie Poster
1 post since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You