Thread: Nested do-while ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    5

    Nested do-while ?

    Code:
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int main () {
        int n=4;
      int myints[] = {1,2,3,4};
     do {
    
         for(int i=0 ; i<n ;i++)
          cout << myints[i];
          cout<<endl;
    
      } while ( next_permutation (myints,myints+2) );
    
      return 0;
    }
    hi , this is the output of the program ;
    1 2 3 4
    2 1 3 4

    now the question is how can i make the output like this ;

    1 2 3 4
    1 2 4 3
    2 1 3 4
    2 1 4 3

    if you realize first 2 number had made a permutation each other and the other last 2 number had a permutation each other ,

    the example is about 4 number making and per 2 of them making permutation ( 2!*2!= 4 possible results )

    from here if you give me the idea i will try to make this code for ' n '

    like we say there are 9 number and per 3 of them makes permutation,(3! *3!*3! = 108 possible results)
    Last edited by bluefare; 04-28-2012 at 04:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with nested ifs
    By marlin in forum C Programming
    Replies: 4
    Last Post: 02-15-2012, 10:17 PM
  2. Nested While
    By skg29 in forum C Programming
    Replies: 4
    Last Post: 10-03-2011, 04:48 AM
  3. Nested Structures Possible?
    By thetinman in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2007, 11:22 AM
  4. nested For loops
    By Chaplin27 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2005, 10:12 AM
  5. Help with using nested For
    By webbizdesign in forum C Programming
    Replies: 5
    Last Post: 09-29-2003, 10:50 PM