The Program in C++ C++ to Create and display unique three-digit number using 1, 2, 3, 4:
#include <iostream>
#include <set>
int main() {
std::set<int> unique_numbers;
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
for (int k = 1; k <= 4; k++) {
if (i != j && j != k && i != k) {
unique_numbers.insert(i * 100 + j * 10 + k);
}
}
}
}
std::cout << "Hello Codeauri Family, Unique three-digit numbers using 1, 2, 3, and 4 are as follows: " << std::endl;
for (const int& number : unique_numbers) {
std::cout << number << " ";
}
return 0;
}
Output:
Hello Codeauri Family, Unique three-digit numbers using 1, 2, 3, and 4 are as follows:
123 124 132 134 142 143 213 214 231 234 241 243 312 314 321 324 341 342 412 413 421 423 431 432
Pro-Tips💡
This program uses three nested loops to generate all possible three-digit numbers using 1, 2, 3, and 4.
The if
statement inside the loops checks for uniqueness, ensuring that no two digits are the same. The numbers are stored in a std::set
to eliminate duplicates and keep only the unique numbers.
Finally, the program displays the unique numbers by iterating through the std::set
and printing each number.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.