69 679
Assignments Done
Successfully Done
In February 2019

Answer to Question #59477 in C++ for Salem

Question #59477
// a program lists all permutations of ABCDEF in which A appears before D

#include <cstring>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

void swap(char *x, char *y)
char temp;
temp = *x;
*x = *y;
*y = temp;

void permute(char *a, int l, int r)
int i;
if (l == r)
cout << "A" << a << endl;
for (i = l; i <= r; i++)
swap((a+l), (a+i));
permute(a, l+1, r);
swap((a+l), (a+i));

int main()
char str[] = "BCDEF";
int n = strlen(str);
permute(str, 0, n-1);

return 0;

How can I make it work correct?
Expert's answer

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


Assignment Expert
27.04.16, 17:58

Dear customer,
Unfortunately, your question requires a lot of work and cannot be done for free.
Please submit it with all requirements as an assignment to our control panel and
we'll assist you.

27.04.16, 01:01

P(6,4)=360 that means we should get 360 different ways to list all the letters "ABCDEF" were A appears before D. This code just prints 18 outputs !!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions