+ 1

Divisors

So a friend of mine proposed a challenge to find all divisors for each number from 1 to 100 I did this, but I want to exclude the number itself from the list of divisors. so for an example l, lets use 6 I want it to display 1, 2 and 3, but not 6. How can I do this? I've tried everything I can think of https://code.sololearn.com/crgVG3IEEMDI/?ref=app

7th Dec 2018, 6:54 PM
Daniel Cooper
Daniel Cooper - avatar
7 Respostas
+ 5
I agree with the answer above. 2. Option: When you think about divisors- what is the biggest divisor of any number (apart from itself)? It's half of the number, right? So you can also write your inner for loop like this: for(int u=1; u<=i/2; u++)
7th Dec 2018, 7:12 PM
dρlυѕρlυѕ
dρlυѕρlυѕ - avatar
+ 3
There are other ways, but this should work too: replace lines 9-15 by if(u == i) { cout << endl; cout << endl; // >:) } else if(i%u == 0) { cout << u << " "; }
7th Dec 2018, 7:00 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 3
Just put a line break in front of Number:
7th Dec 2018, 8:12 PM
dρlυѕρlυѕ
dρlυѕρlυѕ - avatar
+ 2
So I implemented your solution dρlυѕρlυѕ now the first iteration doesn't include a line break.
7th Dec 2018, 7:57 PM
Daniel Cooper
Daniel Cooper - avatar
+ 2
dρlυѕρlυѕ welp that solution was simple and obvious. Lol. Thanks.
7th Dec 2018, 9:05 PM
Daniel Cooper
Daniel Cooper - avatar
+ 2
Don't mention it. 👍
7th Dec 2018, 9:21 PM
dρlυѕρlυѕ
dρlυѕρlυѕ - avatar