-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.c
More file actions
58 lines (53 loc) · 1.07 KB
/
func.c
File metadata and controls
58 lines (53 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
// function to print the array
void printarray(int arr[], int size)
{
int i, j;
for (i = 0; i < size; i++)
{
printf("%d\t", arr[i]);
}
printf("\n");
}
// function to swap the variables
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
// permutation function
void permutation(int *arr, int start, int end)
{
if (start == end)
{
printarray(arr, end + 1);
return;
}
int i;
for (i = start; i <= end; i++)
{
// swapping numbers
swap((arr + i), (arr + start));
// fixing one first digit
// and calling permutation on
// the rest of the digits
permutation(arr, start + 1, end);
swap((arr + i), (arr + start));
}
}
int main()
{
// taking input to the array
int size;
printf("Enter the size of array\n");
scanf("%d", &size);
int i;
int arr[size];
// for (i = 0; i < size; i++)
// scanf("%d", &arr[i]);
// calling permutation function
permutation(arr, 1, 4);
return 0;
}