SHARE
TWEET

ASD Pb 3

madalinaradu May 26th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** p3 combinari n cifre binare care nu au 11 alaturat */
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<conio.h>
  5.  
  6. int sol[20], n = 6;//globale
  7. void afisare() {
  8.     for (int i = 1; i <= n; i++) {
  9.         printf("%3d", sol[i]);
  10.     }
  11.     printf("\n");
  12. }
  13.  
  14. bool valid(int k) {
  15.     //if(k>1 && sol[k] * sol[k-1])
  16.     if(k>1 && sol[k]==sol[k-1] && sol[k]==1)
  17.         return 0;
  18.     return 1;
  19. }
  20.  
  21. void bkt(int k) {
  22.     for (int i = 0; i <= 1; i++) {///i reprezinta multimea de valori posibile pe care o poate lua sol[k] = 0 .. 1
  23.         sol[k] = i;
  24.         if (valid(k)) {
  25.             if (k == n) {
  26.                 afisare();
  27.             } else
  28.                 bkt(k + 1);
  29.         }
  30.     }
  31. }
  32.  
  33. int main() {
  34.     bkt(1);
  35.     _getch();
  36.     return 0;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top