Write a c++ program to accept three digits (i.e 0-9)and print all possible combinations fro these digits.(for exanple if the three digits are 1,2,3 then all possible combinations are 123,132,231,213,312,321 etc)

Showing Answers 1 - 5 of 5 Answers

Yanesh Tyagi

  • Dec 23rd, 2006
 

/* Program to write combination of 3 digit number
   Author : Rachit Tyagi
   Date : 23-Dec-2006 2345 IST
*/
 
#include<iostream.h>
#include<conio.h>
void main(){
 clrscr();
 const int s = 3;
 int a[s];
 int x,y,z;
 for (int i=0; i<s; i++)
  cin >> a[i];
  x = a[0];
  y = a[1];
  z = a[2];
  i = 0;
  cout<<x<<y<<z;
  cout<<"n";
  while(1){
  a[s] = a[i];
  if (i != s - 1){
   a[i] = a[i+1];
   a[i+1] = a[s];
  }
  else {
   a[i] = a[0];
   a[0] = a[s];
   i=-1;
  }
  i++;

  if (a[0] == x && a[1] == y && a[2] == z)
   break;

  for (int j = 0; j < s; j++)
   cout<<a[j];
  cout<<"n";

  }
  getch();

}

  Was this answer useful?  Yes

int a[3]; a[0] = 1; a[1] = 2; a[2] = 3; // Print all the permutations of a three digit number for (int i = 0; i<=2;i++) { for (int j = 0; j<=2;j++) { if(i!=j) { printf("%d",a[i]); printf("%d",a[j]); for (int k = 0; k<=2;k++) { if((i!=k)&& j!=k) { printf("%dn",a[k]); } } } } }

  Was this answer useful?  Yes

sreerag

  • Jul 3rd, 2013
 

Code
  1. #include<iostream.h>

  2. "enter a three digit number""first="<<z<<"

  3. ""second="<<q<<"

  4. ""third="<<w<<"

  5. ""fourth="<<e<<"

  6. ""fifth="<<r<<"

  7. ""sixth="<<t;

  8. }

  Was this answer useful?  Yes

adnan

  • Jan 13th, 2016
 

Code
  1. Yanesh Tyagi

  2.  Dec 23rd, 2006

  3.  

  4. /* Program to write combination of 3 digit number

  5.    Author : Rachit Tyagi

  6.    Date : 23-Dec-2006 2345 IST

  7. */

  8.  

  9. #include<iostream.h>

  10. #include<conio.h>

  11. "n""n"

  Was this answer useful?  Yes

Lineesh K Mohan

  • Mar 22nd, 2016
 

Code
  1. #include<stdio.h>

  2. #include<iostream>

  3. "

  4.  Enter the 3 digit numbers      "

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions