+ 1

Factors and For Loops

Hello! I wrote the following code: https://code.sololearn.com/cT0ubyp9sr0E/?ref=app I was wondering how I could get it to display the factors from large to small, also how do I get rid of the comma on the last factor? For example (*WANT*): 2: 2, 1 3: 3, 1 4: 4, 2, 1 Right now, my code displays: 2: 1, 2, 3: 1, 3, 4: 1, 2, 4, Thank you!!!

4th Oct 2018, 4:11 AM
Miqaela Weller
Miqaela Weller - avatar
3 odpowiedzi
+ 5
Reverse your loop so i is decremented every iteration. This will display your factors in descending order. Print the first member, and in the following loop, print the comma first, then the factor. https://code.sololearn.com/cvrFMB45I1Kb/?ref=app
4th Oct 2018, 4:43 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar
+ 1
thanks so much!!
4th Oct 2018, 4:47 AM
Miqaela Weller
Miqaela Weller - avatar
+ 1
Miqaela Weller You're welcome.
4th Oct 2018, 4:48 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar