programming-examples/c/Search_Sorting/C Program to Generate All Possible Combinations of a Given List of Numbers.c

34 lines
766 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
#include<stdio.h>
#include<string.h>
#define N 10
void print(int *num, int n)
{
int i;
for ( i = 0 ; i < n ; i++)
printf("%d ", num[i]);
printf("\n");
}
int main()
{
int num[N];
int *ptr;
int temp;
int i, n, j;
printf("\nHow many number you want to enter: ");
scanf("%d", &n);
printf("\nEnter a list of numbers to see all combinations:\n");
for (i = 0 ; i < n; i++)
scanf("%d", &num[i]);
for (j = 1; j <= n; j++)
{
for (i = 0; i < n-1; i++)
{
temp = num[i];
num[i] = num[i+1];
num[i+1] = temp;
print(num, n);
}
}
return 0;
}