0% found this document useful (0 votes)
54 views1 page

Email

This document contains code for a recursive function called "fact" that takes in an integer array and integer as parameters. The function recursively permutes the elements of the array by swapping the last element with each preceding element. It also contains a helper function called "print" that outputs the elements of the array.

Uploaded by

abhishek18383
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views1 page

Email

This document contains code for a recursive function called "fact" that takes in an integer array and integer as parameters. The function recursively permutes the elements of the array by swapping the last element with each preceding element. It also contains a helper function called "print" that outputs the elements of the array.

Uploaded by

abhishek18383
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

gaurav.arya@nagarro.

com
public static void fact(int[] arr,int l){
int n = arr.Length;
int s = n - l;
for (int i = 1; i <= l; i++)
{
if (l == n)
{
print(arr);
int tmp = arr[s];
for (int j = s + 1; j < n; j++)
{
arr[j - 1] = arr[j];
}
arr[n - 1] = tmp;
}
else
{
fact(arr, l + 1);
int tmp = arr[s];
for (int j = s + 1; j < n; j++)
{
arr[j - 1] = arr[j];
}
arr[n- 1] = tmp;
}
}
}
public static void print(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
}

You might also like