C++ Examples

WAP in C++ to Create and display unique three-digit number using 1, 2, 3, 4

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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X