Darkphoton - 1 month ago 5

C Question

The objective of the C-program is to print out all the well-ordered numbers between 100 and 999. Well-ordered numbers are numbers that have digits that are at least smaller by 1 when compared to the digit on it's right (e.g. 123, 456, and 159 are all well-ordered numbers).

I start off setting three

`integer`

`x`

`y`

`z`

`1`

`2`

`3`

`z`

`123, 124, 125, .. 129`

`y`

`z`

`y+1`

`while loop`

`100`

`999`

`789`

So far the logic works to print out every well-ordered number between

`100-999`

`789`

`689`

`x`

`x`

`789`

Also the problem I'm working on mentions to print only 10 numbers before returning, and I also couldn't find a way to do this. I'm quite new to the C language so I was wondering if anyone can figure this out and give me some hints or guidance? Have I completely gone about this the wrong way and there is a simpler way to do this?

Thank you all for helping in advance.

`#include <stdio.h>`

#include <stdlib.h>

int main(void) {

int x, y, z;

x = 1;

y = 2;

z = 3;

while(x != 7 || y != 8 || z != 9) {

printf("%d%d%d \n", x, y, z); // print well-ordered number

if(y==8) {

x++; // only increment x when y is reached the last position

y = x+1; // put y in the next correct position

z = y; // put z in the next correct position

}

if(z==9) {

y++; // only increment y when z's reached the last position

z = y; // reset z's position

}

z++; // increment z as it's always the first priority to maintain a well-ordered number

}

return 0;

}