program

i want to know the coding of a program and that program is


write a program that inputs three digits and displays all possible combinations of these digits
for example;if we enter three digits 1,2,3
then possible combinations are
123
321
213
312
321
"permutation" is the correct word for this. all 6 permutations you showed is single combination.


search for "next_permutation" in <algorithm>
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <algorithm> ///next_permutation
using namespace std;

int main(){
    int a,b,c;
    cout<<"Please enter your three digits: ";
    cin>>a;cin>>b;cin>>c;
    int myints[] = {a,b,c};
    sort (myints,myints+3);
    do{cout<<myints[0]<<myints[1]<<myints[2]<<'\n';
    }while(next_permutation(myints,myints+3));
    return 0;}
Last edited on
Topic archived. No new replies allowed.