# Program to print all three digit numbers in ascending order

Last Updated : 10 Feb, 2024

Write a program to print all the three-digit numbers in ascending order.

Output Format:

100 101 102…till 999

Approach: Using for Loop to print all the three Digit Numbers:

Use for loop to iterate from the smallest three-digit number, that is 100 till we reach the largest three-digit number, that is 999 and, in every iteration, print the number. After reaching 999, we will have all the three-digit numbers in ascending order.

Step-by-step algorithm:

• Initialize a counter to the smallest 3-digit number i.e. 100.
• Run a for loop till the greatest 3-digit number i.e. 999.
• For each iteration print the number

Below is the implementation of the above approach:

## C++

 `#include ` `using` `namespace` `std;`   `// Function to print all the three-digit numbers in` `// ascending order` `void` `print3DigitNums()` `{` `    ``for` `(``int` `count = 100; count <= 999; count++) {` `        ``cout << count << endl;` `    ``}` `}`   `// Driver code` `int` `main()` `{` `    ``cout` `        ``<< ``"All three digit numbers in ascending order: \n"``;` `    ``print3DigitNums();` `}`

## Java

 `public` `class` `GFG {` `    ``// Function to print all the three-digit numbers in ascending order` `    ``public` `static` `void` `print3DigitNums() {` `        ``for` `(``int` `count = ``100``; count <= ``999``; count++) {` `            ``System.out.println(count);` `        ``}` `    ``}`   `    ``// Driver code` `    ``public` `static` `void` `main(String[] args) {` `        ``System.out.println(``"All three-digit numbers in ascending order: "``);` `        ``print3DigitNums();` `    ``}` `}`   `// This code is contributed by Yash Agarwal(yashagarwal2852002)`

## Python3

 `# Function to print all the three-digit numbers in` `# ascending order` `def` `print_3_digit_nums():` `    ``for` `count ``in` `range``(``100``, ``1000``):` `        ``print``(count)`   `# Driver code` `if` `__name__ ``=``=` `"__main__"``:` `    ``print``(``"All three digit numbers in ascending order:"``)` `    ``print_3_digit_nums()`

## C#

 `using` `System;`   `class` `GFG` `{` `    ``// Function to print all the three-digit numbers in ascending order` `    ``public` `static` `void` `print3DigitNums()` `    ``{` `        ``for` `(``int` `count = 100; count <= 999; count++)` `        ``{` `            ``Console.WriteLine(count);` `        ``}` `    ``}`   `    ``// Driver code` `    ``public` `static` `void` `Main(``string``[] args)` `    ``{` `        ``Console.WriteLine(``"All three-digit numbers in ascending order: "``);` `        ``print3DigitNums();` `    ``}` `}`

## Javascript

 `// Function to print all the three-digit ` `// numbers in ascending order` `function` `print3DigitNums() {` `    ``for` `(let count = 100; count <= 999; count++) {` `        ``console.log(count);` `    ``}` `}`   `// Driver code` `console.log(``"All three digit numbers in ascending order: "``);` `print3DigitNums();`

Output

```All three digit numbers in ascending order:
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138...

```

Time Complexity: O(1000) = O(1)
Auxiliary Space: O(1)

Previous
Next