What will be the output of the following code?
#include <stdio.h>
#include <string.h>
#include <iostream.h>
using namespace std;
void swap(char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
void func(char *a, int l, int r)
{
int i;
if (l == r)
cout<<a<<” ,”;
else
{
for (i = l; i <= r; i++)
{
swap((a+l), (a+i));
func(a, l+1, r);
swap((a+l), (a+i));
}
}
}
int main()
{
char str[] = "AA";
int n = strlen(str);
func(str, 0, n-1);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <iostream.h>
using namespace std;
void swap(char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
void func(char *a, int l, int r)
{
int i;
if (l == r)
cout<<a<<” ,”;
else
{
for (i = l; i <= r; i++)
{
swap((a+l), (a+i));
func(a, l+1, r);
swap((a+l), (a+i));
}
}
}
int main()
{
char str[] = "AA";
int n = strlen(str);
func(str, 0, n-1);
return 0;
}
A. AA,
B. AA,AA
C. A,A
D. AA,AA,
Answer: Option D
Join The Discussion