Add to Favorites    Make Home Page 9688 Online  
 Language Categories  
 Our Services  

Home » C++ Home » Mathematics Home » PROGRAM TO PRINT ALL POSSIBLE PERMUTATIONS OF FIRST N NAUTURAL NOs

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title PROGRAM TO PRINT ALL POSSIBLE PERMUTATIONS OF FIRST N NAUTURAL NOs
Author Shikha Jain
Author Email shi_81 [at] rediffmail.com
Description
Category C++ » Mathematics
Hits 12580
Code Select and Copy the Code
//PROGRAM TO PRINT ALL POSSIBLE PERMUTATIONS //OF FIRST N NAUTURAL NOS /******************************************/ /* DEVELOPED BY :- */ /* SHIKHA JAIN */ /******************************************/ /* /* MAIN LOGIC : /*PERMUTATIONS CAN BE FIND OUT BY LEFT SHIFTING AS FOLLOWS /* /* 1234 /* / | | /* 2341 3412 4123 1234 //AFTER SHIFTING ALL THE N DIGITS /* / | / | / | / | /*2413 2134 2341 . . . 4231 4312 4123 . . . //KEEPING FIRST DIGIT FIXED /* / / / / / / / / / / / / /* 2143 2134 4213 4231 .............. //KEEPING 1 & 2 DIGITS FIXED /* /*LIKEWISE AFTER THE LAST STEP THAT IS KEEPING ALL THE DIGITS FIXED /*EXCEPT TH ELAST ONE & DO SHIFTING WITH THOSE TWO DIGITS, WE WILL /*GET n! LEAF NODE SUCH THAT EACH NODE IS REPRESENTING A NEW /*ARRANGEMENT OF FIRST N NATURAL NOS. /******************************************/ //header files #include<iostream.h> #include<conio.h> #include<string.h> int count=0; //func to display the sequence void dis(char a[],int n) { for(int jk=n-1;jk>=0;jk--) { cout<<a[jk]; } cout<<" "; } //function to left shift last n elements //of the array by one position void shift(char a[],int n) { char s; s=a[n-1]; for(int i=n-1;i>0;i--) a[i]=a[i-1]; a[0]=s; } //func to find all possible arrangements void per(char a[],int m,int n) { for(int i=0;i<m;i++) { if(m>1) { shift(a,m); per(a,m-1,n); //genetrating the tree } else { dis(a,n); //displaying the leaf nodes of the tree count++; } } } void main() { // char *a; int n; clrscr(); cout<<"Enter a no : "; cin>>n; char *a = new (char[n]); for(int i=0;i<n;i++) a[i] = n-i+48; // dis(a,n); cout<<"Possible permutations are : "; per(a,n,n); cout<<"Total No Of Permutations Is "<<count; getch(); } /**************************************/ OUTPUT ------ Enter a no : 3 Possible permutations are : 213 231 321 312 132 123 Total No Of Permutations Is 6 /**************************************/

Related Source Codes

Script Name Author
Moving ball screen saver karlmarx
The Classic Game of Snake & Ladder Lakshmi Narayana .A
Railway seat reservation question which comes in sapient VyomWorld
To calculate percentile Ravi Mathur
Send to folder ANIMESH SAHU
Analog clock and calendar Nazia & Rida
HIGH/LOW GAME MOLLY ARORA
Data structure (stack Implimentation) Swapnil B Adsure
Memory Game AnirudhSanyal
Easy Calc Anirudh Sanyal
GK Quiz Anirudh Sanyal
Hangman Game Manish Jain
Snakeman Manish Jain
Full month Calendar Nigi
Cursor shapes nigi

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions
Copyright ©2003-2017 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=672


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review