Advertisement
a53

Permutari6

a53
Nov 15th, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a , b , n , x[10];
  6.  
  7. bool OK(int k)
  8. {
  9. for(int i =1 ; i < k ; i ++)
  10. if(x[k] == x[i])
  11. return false;
  12. return true;
  13. }
  14.  
  15. void Afisare()
  16. {
  17. for(int i = 1 ; i <= n ; i ++)
  18. cout << x[i] << " ";
  19. cout << '\n';
  20. }
  21.  
  22. void Back(int k)
  23. {
  24. for(int i = a ; i <= b ; i ++)
  25. {
  26. x[k] = i;
  27. if(OK(k))
  28. {
  29. if(k == n)
  30. Afisare();
  31. else
  32. Back(k + 1);
  33. }
  34. }
  35. }
  36.  
  37. int main()
  38. {
  39. cin >> a >> b;
  40. n = b - a + 1;
  41. Back(1);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement