+ 1
Possible combinations
Write a program to accept three digits (i.e., 0-9)and print all possible combinations from these digits. for example, if the three digits are 1, 2 and 3 then all possible combinations are 123, 132, 23 1, 213, 312 and 321.
6 ответов
+ 2
Thank you
+ 1
include<iostream>
int main()
{
int a[3];
cout<<"Enter three digits :"<<endl;
cin>>a[0]>>a[1]>>a[2];
for (int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
for (int k=0;k<3;k++)
{
if (i!=j&&i!=k&&j!=k)
cout<<endl<<endl<<a[i]<<a[j]<<a[k];
}
}
}
return 0 ;
}
This is the code but I am not getting the correct answer by executing this code..
+ 1
Then what will be the code..???
+ 1
Heena Parween Here's my attempt. The permute function swap the value of the array's elements then print the modified array. You can modify the code to get user input and use other concept for further optimization.
https://code.sololearn.com/cde3K9Hyl0d0/?ref=app
0
More like permutation than combination. Is this a question or a challenge you're proposing?
0
cout << a[i] << a[j] << a[k] will always print the same result unless you:
1. Modify how the result is printed to the console.
2. Modify the array elements.