Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- const int count = 4;
- char *elements[] = { "box", "board", "table", "apple" };
- int array[count] = { 0, 1, 2, 3};
- int fact(int a);
- void perestanovka(int position,int current);
- int main(){
- perestanovka(0,1);
- return 0;
- }
- void perestanovka(int position, int current){
- for (int i = 0; i < count; i++)
- printf("%s ", elements[array[i]]);
- printf("\n");
- if (current != fact(count)){
- int tmp = array[position];
- array[position] = array[position + 1];
- array[position + 1] = tmp;
- if (position + 2 < count)
- perestanovka(position + 1, current + 1);
- else
- perestanovka(0, current + 1);
- }
- }
- int fact(int a){
- if (a == 0 || a == 1)
- return 1;
- else
- return a*fact(a - 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment