Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define NMAX 10
- void display(int arr[]) {
- for (int i = 0; i < NMAX; i++) {
- printf("%d ", arr[i]);
- }
- puts("");
- }
- void bktr(int k, int arr[]) {
- if (k == NMAX - 1) {
- display(arr);
- return;
- }
- for (int i = 0; i < NMAX; i++) {
- if ((arr[k - 1] % 2 == 0 && i % 2 == 0) || (k == NMAX-2 && i %2==0)) {
- continue;
- }
- arr[k] = i;
- bktr(k + 1, arr);
- }
- }
- int main(void) {
- static int arr[NMAX] = {0, 7, 9, 9};
- bktr(4, arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement