ParanoidPanda

Untitled

Dec 24th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. const int count = 4;
  5. char *elements[] = { "box", "board", "table", "apple" };
  6. int array[count] = { 0, 1, 2, 3};
  7.  
  8. int fact(int a);
  9. void perestanovka(int position,int current);
  10.  
  11. int main(){
  12. perestanovka(0,1);
  13. return 0;
  14. }
  15.  
  16. void perestanovka(int position, int current){
  17. for (int i = 0; i < count; i++)
  18. printf("%s ", elements[array[i]]);
  19. printf("\n");
  20. if (current != fact(count)){
  21. int tmp = array[position];
  22. array[position] = array[position + 1];
  23. array[position + 1] = tmp;
  24. if (position + 2 < count)
  25. perestanovka(position + 1, current + 1);
  26. else
  27. perestanovka(0, current + 1);
  28. }
  29.  
  30. }
  31.  
  32. int fact(int a){
  33. if (a == 0 || a == 1)
  34. return 1;
  35. else
  36. return a*fact(a - 1);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment