# While Loop

An ascending integer occurs when each digit is greater than any digit that precedes it. An example is

478. Write a program that finds the number of ascending integers between 200 and 300.

I know how to do basic while loops but cannot figure out how to separate a number and determine if it is an ascending integer.

C++.

`#include <iostream> int d1 = 2; int d2 = d1 + 1; int main(){ while(d2<10) { int d3 = d2 + 1; while (d3<10) { int number = d1*100+d2*10+d3; std::cout<<number; std::endl; d3++; } d2++; } }`

pls do `std::endl`

xd i mean its just user preference

@realTronsibut the thing is `std::endl`

is better because some people use `\r\n`

so you *could have just gotten garbled text* jk jk most os now do that convert automatically

After thinking about this problem, I got to this solution.

`#include <iostream> #include <vector> int main() { unsigned int hundred = 2, ten = 0, one = 0; std::vector<int> nums; while (hundred < 3) { while (ten < 10) { while (one < 10) { one ++; if (hundred < ten && ten < one) { nums.push_back(100 * hundred + 10 * ten + one); } } one = 0; ten++; } ten = 0; hundred ++; } for (int i : nums) { std::cout << i << " "; } std::cout << std::endl; return 0; }`

thank god for 0!

Hmm there's an extraneous 300 in there, how strnage

basic permutation as such:

23_ ,4-9: 6 possibilities

24_ ,5-9: 5 possibilities,

etc.

Your script gave these numbers:

`234 235 236 237 238 239 240 245 246 247 248 249 250 256 257 258 259 260 267 268 269 270 278 279 280 289 290 300`

some such as `280`

aren't ascending, and you also missed a few

`num.size()`

iirc

yeah unfortunately i did a bad plz read the marked one

@realTronsi`//I'm not gonnna write actual code since I don't know much cpp but this is the actual logic: digit2 = digit1 + 1 while digit2 < 10 digit3 = digit2 + 1 while digit3 < 10 cout << digit1*100 + digit2*10 + digit3 digit3++ digit2++`

(not actual code since idk much cpp but there is no point in looping over every single number.)

hey does it not work?

@realTronsiit stores all the integers, and if I took the time to study permutations, it might be more elegant.

@realTronsiSomething like:

3*2 * 8! * 7!

should suffice but it doesn't i don't think

@realTronsi

indeed plz helpz makez betterz

@realTronsiOH RIGHT i should probably skip a few numbers yes yes

@realTronsi`let d1 = 2 let d2 = d1+1 while(d2<10){ let d3 = d2+1; while(d3<10){ console.log(d1*100+d2*10+d3) d3++ } d2++ }`

This extremely short chunk of code in js works, (just an extra 9 at the end that can easily be solved)

hmm true, but whats with the 9 anyways

@realTronsic++ god

@realTronsi`int d1 = 2; int d2 = d1 + 1; do { int d3 = d3 + 1; do { std::cout<<d1*100+d2*10+d3<< d3++ } while (d3<10); d2++ } while(d2<10);`

there might be syntax errors since im not the best cpp

`#include <iostream> int d1 = 2; int d2 = d1 + 1; while(d2<10) { int d3 = d3 + 1; while (d3<10) { std::cout<<d1*100+d2*10+d3<< d3++; } d2++; }`

theres an error `unqualifed-id`

idk how to fix but anyways theres code

hol' up why is there an extra `<<`

what lang?

alright!

@WILLIAMMACDONALplease read the question thanks

@RYANTADIPARTHIbtw your example won't work endl isn't defined

@RYANTADIPARTHIactually read the question smh smh

@RYANTADIPARTHI
So sorry about that, logic mistakes :(

If you need I can explain the code to you, but it should be pretty straightforward (I think)

np :)

@WILLIAMMACDONAL