Advertisement
STANAANDREY

sda bktr

Dec 16th, 2023 (edited)
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define NMAX 10
  4.  
  5. void display(int arr[]) {
  6.     for (int i = 0; i < NMAX; i++) {
  7.         printf("%d ", arr[i]);
  8.     }
  9.     puts("");
  10. }
  11.  
  12. void bktr(int k, int arr[]) {
  13.     if (k == NMAX - 1) {
  14.         display(arr);
  15.         return;
  16.     }
  17.     for (int i = 0; i < NMAX; i++) {
  18.         if ((arr[k - 1] % 2 == 0 && i % 2 == 0) || (k == NMAX-2 && i %2==0)) {
  19.             continue;
  20.         }
  21.         arr[k] = i;
  22.         bktr(k + 1, arr);
  23.     }
  24. }
  25.  
  26. int main(void) {
  27.     static int arr[NMAX] = {0, 7, 9, 9};
  28.     bktr(4, arr);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement