1
   

How to do a program that asks the user positive integer and then prints its factors in in descending

 
 
Wed 7 Mar, 2012 02:47 am
How to do a program that asks the user positive integer and then prints its factors in in descending order? If number is 120, then its factors are 5, 3, 2, 2, 2.
Some help please, thank you.
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 1 • Views: 2,617 • Replies: 2
Topic Closed
No top replies

 
George
 
  2  
Wed 7 Mar, 2012 11:19 am
@alvoutila,
To begin with, the factors of 120 are
2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40 and 60.

I'd suggest using a loop, initializing the index to 2 and stopping when the index
is equal to the number input.
Within the loop first divide input by the index and determine whether there
is no remainder (use modulo).
If there's no remainder, then save the index and the quotient in a list.
Also save the higher of the two numbers, replacing the previous higher
number.
As you continue to loop, you can break out of the loop once the index is equal
to the saved higher number.
At the end, sort the list in descending order and display it.
maxdancona
 
  1  
Fri 1 Nov, 2013 03:48 pm
@George,
I think the example gave prime factors. I suspect that might be the assignment.
0 Replies
 
 

Related Topics

Clone of Micosoft Office - Question by Advocate
Do You Turn Off Your Computer at Night? - Discussion by Phoenix32890
The "Death" of the Computer Mouse - Discussion by Phoenix32890
Windows 10... - Discussion by Region Philbis
Surface Pro 3: What do you think? - Question by neologist
Windows 8 tips thread - Discussion by Wilso
GOOGLE CHROME - Question by Setanta
.Net and Firefox... - Discussion by gungasnake
Hacking a computer and remote access - Discussion by trying2learn
 
  1. Forums
  2. » How to do a program that asks the user positive integer and then prints its factors in in descending
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 04/25/2024 at 10:11:19