Advertisement
Guest User

MASAKIs

a guest
Oct 17th, 2007
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5. int cnt;
  6.  
  7. void boolean_truth_table(int n, char prev[30] = "")
  8. {
  9.     if(n == 1)
  10.     {
  11.         cout << prev << "true" << endl;
  12.         cout << prev << "false" << endl;
  13.         cnt += 2;
  14.         return;
  15.     }
  16.     else
  17.     {
  18.         char cur[30];
  19.  
  20.         strcpy(cur, prev);
  21.         strcat(cur, "true ");
  22.         boolean_truth_table(n - 1, cur);
  23.  
  24.         strcpy(cur, prev);
  25.         strcat(cur, "false ");
  26.         boolean_truth_table(n - 1, cur);
  27.     }
  28. }
  29.  
  30. int main()
  31. {
  32.     int n;
  33.     cnt = 0;
  34.  
  35.     cout << "How many boolean variables?? ";
  36.     cin >> n;
  37.  
  38.     boolean_truth_table(n);
  39.  
  40.     cout << "total count: " << cnt << endl;
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement