SlideShare a Scribd company logo
1 of 3
Download to read offline
#include
#include
/* Function swaps to pointers */
void swap(char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
/* recursive function to print permutations */
void permutation(char *a, int l, int r)
{
int i;
if (l == r)
printf("%s ", a);
else
{
for (i = l; i <= r; i++)
{
swap((a+l), (a+i));
permutation(a, l+1, r);
swap((a+l), (a+i)); //backtrack
}
}
}
/* factorial method*/
int factorial(int n){
if(n==0)
return 1;
else
return n*factorial(n-1);
}
/* Main function */
int main()
{
char str[] = "ABC";
int n = strlen(str);
permutation(str, 0, n-1);
int fact = factorial(n);
printf("Total permutations: %d ",fact);
return 0;
}
/*
sample output
*/
Solution
#include
#include
/* Function swaps to pointers */
void swap(char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
/* recursive function to print permutations */
void permutation(char *a, int l, int r)
{
int i;
if (l == r)
printf("%s ", a);
else
{
for (i = l; i <= r; i++)
{
swap((a+l), (a+i));
permutation(a, l+1, r);
swap((a+l), (a+i)); //backtrack
}
}
}
/* factorial method*/
int factorial(int n){
if(n==0)
return 1;
else
return n*factorial(n-1);
}
/* Main function */
int main()
{
char str[] = "ABC";
int n = strlen(str);
permutation(str, 0, n-1);
int fact = factorial(n);
printf("Total permutations: %d ",fact);
return 0;
}
/*
sample output
*/

More Related Content

Similar to #include stdio.h #include string.h Function swaps to po.pdf

Similar to #include stdio.h #include string.h Function swaps to po.pdf (20)

VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
 
C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdf
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdf
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 
6. function
6. function6. function
6. function
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
Function recap
Function recapFunction recap
Function recap
 
Function recap
Function recapFunction recap
Function recap
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
week-15x
week-15xweek-15x
week-15x
 
7 functions
7  functions7  functions
7 functions
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
week-20x
week-20xweek-20x
week-20x
 
Vcs29
Vcs29Vcs29
Vcs29
 
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docxGIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
 
Cpds lab
Cpds labCpds lab
Cpds lab
 

More from galagirishp

alcohols also do not give tollens test.... only a.pdf
                     alcohols also do not give tollens test.... only a.pdf                     alcohols also do not give tollens test.... only a.pdf
alcohols also do not give tollens test.... only a.pdfgalagirishp
 
Acid Buffer - Weak acid + plus its salt Basic B.pdf
                     Acid Buffer - Weak acid + plus its salt Basic B.pdf                     Acid Buffer - Weak acid + plus its salt Basic B.pdf
Acid Buffer - Weak acid + plus its salt Basic B.pdfgalagirishp
 
Total vapor pressure of mixture = P(benzene) + P(.pdf
                     Total vapor pressure of mixture = P(benzene) + P(.pdf                     Total vapor pressure of mixture = P(benzene) + P(.pdf
Total vapor pressure of mixture = P(benzene) + P(.pdfgalagirishp
 
some data is missin .pdf
                     some data is missin                              .pdf                     some data is missin                              .pdf
some data is missin .pdfgalagirishp
 
reaction is missing .pdf
                     reaction is missing                              .pdf                     reaction is missing                              .pdf
reaction is missing .pdfgalagirishp
 
Not necessarily. It could very well mean that you.pdf
                     Not necessarily. It could very well mean that you.pdf                     Not necessarily. It could very well mean that you.pdf
Not necessarily. It could very well mean that you.pdfgalagirishp
 
For Li, B, and F they only formed single bond bet.pdf
                     For Li, B, and F they only formed single bond bet.pdf                     For Li, B, and F they only formed single bond bet.pdf
For Li, B, and F they only formed single bond bet.pdfgalagirishp
 
Enzyme Induction- the synthesis of enzymes in res.pdf
                     Enzyme Induction- the synthesis of enzymes in res.pdf                     Enzyme Induction- the synthesis of enzymes in res.pdf
Enzyme Induction- the synthesis of enzymes in res.pdfgalagirishp
 
Buffer Capacity is the ranges of volume of acid o.pdf
                     Buffer Capacity is the ranges of volume of acid o.pdf                     Buffer Capacity is the ranges of volume of acid o.pdf
Buffer Capacity is the ranges of volume of acid o.pdfgalagirishp
 
a. CH4 has no free valence electrons so it can no.pdf
                     a. CH4 has no free valence electrons so it can no.pdf                     a. CH4 has no free valence electrons so it can no.pdf
a. CH4 has no free valence electrons so it can no.pdfgalagirishp
 
We are living in a world where cyber security is a top priority for .pdf
We are living in a world where cyber security is a top priority for .pdfWe are living in a world where cyber security is a top priority for .pdf
We are living in a world where cyber security is a top priority for .pdfgalagirishp
 
highest bond energy molecule is CO because its bond order is = 3.pdf
highest bond energy molecule is CO because its bond order is = 3.pdfhighest bond energy molecule is CO because its bond order is = 3.pdf
highest bond energy molecule is CO because its bond order is = 3.pdfgalagirishp
 
Urine is concentrated byc) facilitated diffusion in the collecting d.pdf
Urine is concentrated byc) facilitated diffusion in the collecting d.pdfUrine is concentrated byc) facilitated diffusion in the collecting d.pdf
Urine is concentrated byc) facilitated diffusion in the collecting d.pdfgalagirishp
 
The two fund theorem is the establishment of two efficient Funds.pdf
The two fund theorem is the establishment of two efficient Funds.pdfThe two fund theorem is the establishment of two efficient Funds.pdf
The two fund theorem is the establishment of two efficient Funds.pdfgalagirishp
 
the nuclide is147N which is nitrogenSolutionthe nuclide .pdf
the nuclide is147N which is nitrogenSolutionthe nuclide .pdfthe nuclide is147N which is nitrogenSolutionthe nuclide .pdf
the nuclide is147N which is nitrogenSolutionthe nuclide .pdfgalagirishp
 
The Programmer has created multiple entry point which can be used to.pdf
The Programmer has created multiple entry point which can be used to.pdfThe Programmer has created multiple entry point which can be used to.pdf
The Programmer has created multiple entry point which can be used to.pdfgalagirishp
 
The halide is iodine as it gives pale yellow precipitate with AgNO3 .pdf
The halide is iodine as it gives pale yellow precipitate with AgNO3 .pdfThe halide is iodine as it gives pale yellow precipitate with AgNO3 .pdf
The halide is iodine as it gives pale yellow precipitate with AgNO3 .pdfgalagirishp
 
The answer isd. The pi electrons are distributed over the entire .pdf
The answer isd. The pi electrons are distributed over the entire .pdfThe answer isd. The pi electrons are distributed over the entire .pdf
The answer isd. The pi electrons are distributed over the entire .pdfgalagirishp
 
Modified Code Game.java­import java.util.;public class Game.pdf
Modified Code Game.java­import java.util.;public class Game.pdfModified Code Game.java­import java.util.;public class Game.pdf
Modified Code Game.java­import java.util.;public class Game.pdfgalagirishp
 
(a)Solution(a).pdf
(a)Solution(a).pdf(a)Solution(a).pdf
(a)Solution(a).pdfgalagirishp
 

More from galagirishp (20)

alcohols also do not give tollens test.... only a.pdf
                     alcohols also do not give tollens test.... only a.pdf                     alcohols also do not give tollens test.... only a.pdf
alcohols also do not give tollens test.... only a.pdf
 
Acid Buffer - Weak acid + plus its salt Basic B.pdf
                     Acid Buffer - Weak acid + plus its salt Basic B.pdf                     Acid Buffer - Weak acid + plus its salt Basic B.pdf
Acid Buffer - Weak acid + plus its salt Basic B.pdf
 
Total vapor pressure of mixture = P(benzene) + P(.pdf
                     Total vapor pressure of mixture = P(benzene) + P(.pdf                     Total vapor pressure of mixture = P(benzene) + P(.pdf
Total vapor pressure of mixture = P(benzene) + P(.pdf
 
some data is missin .pdf
                     some data is missin                              .pdf                     some data is missin                              .pdf
some data is missin .pdf
 
reaction is missing .pdf
                     reaction is missing                              .pdf                     reaction is missing                              .pdf
reaction is missing .pdf
 
Not necessarily. It could very well mean that you.pdf
                     Not necessarily. It could very well mean that you.pdf                     Not necessarily. It could very well mean that you.pdf
Not necessarily. It could very well mean that you.pdf
 
For Li, B, and F they only formed single bond bet.pdf
                     For Li, B, and F they only formed single bond bet.pdf                     For Li, B, and F they only formed single bond bet.pdf
For Li, B, and F they only formed single bond bet.pdf
 
Enzyme Induction- the synthesis of enzymes in res.pdf
                     Enzyme Induction- the synthesis of enzymes in res.pdf                     Enzyme Induction- the synthesis of enzymes in res.pdf
Enzyme Induction- the synthesis of enzymes in res.pdf
 
Buffer Capacity is the ranges of volume of acid o.pdf
                     Buffer Capacity is the ranges of volume of acid o.pdf                     Buffer Capacity is the ranges of volume of acid o.pdf
Buffer Capacity is the ranges of volume of acid o.pdf
 
a. CH4 has no free valence electrons so it can no.pdf
                     a. CH4 has no free valence electrons so it can no.pdf                     a. CH4 has no free valence electrons so it can no.pdf
a. CH4 has no free valence electrons so it can no.pdf
 
We are living in a world where cyber security is a top priority for .pdf
We are living in a world where cyber security is a top priority for .pdfWe are living in a world where cyber security is a top priority for .pdf
We are living in a world where cyber security is a top priority for .pdf
 
highest bond energy molecule is CO because its bond order is = 3.pdf
highest bond energy molecule is CO because its bond order is = 3.pdfhighest bond energy molecule is CO because its bond order is = 3.pdf
highest bond energy molecule is CO because its bond order is = 3.pdf
 
Urine is concentrated byc) facilitated diffusion in the collecting d.pdf
Urine is concentrated byc) facilitated diffusion in the collecting d.pdfUrine is concentrated byc) facilitated diffusion in the collecting d.pdf
Urine is concentrated byc) facilitated diffusion in the collecting d.pdf
 
The two fund theorem is the establishment of two efficient Funds.pdf
The two fund theorem is the establishment of two efficient Funds.pdfThe two fund theorem is the establishment of two efficient Funds.pdf
The two fund theorem is the establishment of two efficient Funds.pdf
 
the nuclide is147N which is nitrogenSolutionthe nuclide .pdf
the nuclide is147N which is nitrogenSolutionthe nuclide .pdfthe nuclide is147N which is nitrogenSolutionthe nuclide .pdf
the nuclide is147N which is nitrogenSolutionthe nuclide .pdf
 
The Programmer has created multiple entry point which can be used to.pdf
The Programmer has created multiple entry point which can be used to.pdfThe Programmer has created multiple entry point which can be used to.pdf
The Programmer has created multiple entry point which can be used to.pdf
 
The halide is iodine as it gives pale yellow precipitate with AgNO3 .pdf
The halide is iodine as it gives pale yellow precipitate with AgNO3 .pdfThe halide is iodine as it gives pale yellow precipitate with AgNO3 .pdf
The halide is iodine as it gives pale yellow precipitate with AgNO3 .pdf
 
The answer isd. The pi electrons are distributed over the entire .pdf
The answer isd. The pi electrons are distributed over the entire .pdfThe answer isd. The pi electrons are distributed over the entire .pdf
The answer isd. The pi electrons are distributed over the entire .pdf
 
Modified Code Game.java­import java.util.;public class Game.pdf
Modified Code Game.java­import java.util.;public class Game.pdfModified Code Game.java­import java.util.;public class Game.pdf
Modified Code Game.java­import java.util.;public class Game.pdf
 
(a)Solution(a).pdf
(a)Solution(a).pdf(a)Solution(a).pdf
(a)Solution(a).pdf
 

Recently uploaded

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 

Recently uploaded (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 

#include stdio.h #include string.h Function swaps to po.pdf

  • 1. #include #include /* Function swaps to pointers */ void swap(char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } /* recursive function to print permutations */ void permutation(char *a, int l, int r) { int i; if (l == r) printf("%s ", a); else { for (i = l; i <= r; i++) { swap((a+l), (a+i)); permutation(a, l+1, r); swap((a+l), (a+i)); //backtrack } } } /* factorial method*/ int factorial(int n){ if(n==0) return 1; else return n*factorial(n-1); }
  • 2. /* Main function */ int main() { char str[] = "ABC"; int n = strlen(str); permutation(str, 0, n-1); int fact = factorial(n); printf("Total permutations: %d ",fact); return 0; } /* sample output */ Solution #include #include /* Function swaps to pointers */ void swap(char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } /* recursive function to print permutations */ void permutation(char *a, int l, int r) { int i; if (l == r) printf("%s ", a); else {
  • 3. for (i = l; i <= r; i++) { swap((a+l), (a+i)); permutation(a, l+1, r); swap((a+l), (a+i)); //backtrack } } } /* factorial method*/ int factorial(int n){ if(n==0) return 1; else return n*factorial(n-1); } /* Main function */ int main() { char str[] = "ABC"; int n = strlen(str); permutation(str, 0, n-1); int fact = factorial(n); printf("Total permutations: %d ",fact); return 0; } /* sample output */