How can I output numbers that evenly divide to the all the positive numbers up until the user's input number? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

How can I output numbers that evenly divide to the all the positive numbers up until the user's input number?

The user inputs a positive number. Then the computer outputs all the numbers less than or equal to the user's input number. Below each number, the computer outputs numbers that evenly divide to that number. I want the computer to output the numbers that have no remainders. For example, if the input is 15, the output would be: 15-> 1, 3, 5. But, it will also do the same for every positve number before 15. Ex: 1-> 1 2-> 1 2 3-> 1 3 ..... 15-> 1 3 5 15

27th Feb 2017, 7:37 PM
Poppy
Poppy - avatar
2 Antworten
+ 2
for(int i=1;i<input;i++) { if(input%i==0) { cout<<i<<endl; for(int j=1;j<i;j++) { if(i%j==0) { cout<<j<<endl; }}}} //edit: sorry, that'll output the divisors of the divisors of the input ^^
27th Feb 2017, 7:54 PM
Mario L.
Mario L. - avatar
+ 2
//evaluate all numbers until half the input for (int i=1; i<=input/2;i++){ if (input%i==0){//print only the divisors cout<<i<<endl; } }
27th Feb 2017, 8:18 PM
seamiki
seamiki - avatar