can't print all the permutations of a number

This is a discussion on can't print all the permutations of a number within the C++ Programming forums, part of the General Programming Boards category; hey,i was just tryin my hand at this program which prints all the possible permutations of a number and m ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    1

    can't print all the permutations of a number

    hey,i was just tryin my hand at this program which prints all the possible permutations of a number and m stuck up wid d code.
    the code i wrote was:


    Code:
    #include<iostream.h>
    #include<conio.h>
    int x;
    void main()
    {
       int arr[20],num;
       cout<<"enter the number of digits:"<<endl;
       cin>>num;
       cout<<"enter the number:"<<endl;
       for(int i=0;i<num;i++)
       {
          cin>>arr[i];
       }
       for(int j=0;j<num;j++)
       {
       for(int k=0;k<num;k++)
       {
         for(int l=0;l<num;l++)
         {
    	cout<<endl;
    	cout<<arr[l];
         }
        x=arr[num-1];
         for(int m=0;m<num-1;m++)
         {
           arr[m+1]=arr[m];
         }
         arr[j]=x;
       }
       }
       getch();
      }
    please tel me what changes to make in the code

  2. #2
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Try using #include <algorithm>

    ... perhaps.

    Or check out the snippets at the entrance page.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Replies: 6
    Last Post: 02-19-2009, 06:19 PM
  3. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  4. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM
  5. Replies: 4
    Last Post: 03-09-2002, 12:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21