Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- int cnt;
- void boolean_truth_table(int n, char prev[30] = "")
- {
- if(n == 1)
- {
- cout << prev << "true" << endl;
- cout << prev << "false" << endl;
- cnt += 2;
- return;
- }
- else
- {
- char cur[30];
- strcpy(cur, prev);
- strcat(cur, "true ");
- boolean_truth_table(n - 1, cur);
- strcpy(cur, prev);
- strcat(cur, "false ");
- boolean_truth_table(n - 1, cur);
- }
- }
- int main()
- {
- int n;
- cnt = 0;
- cout << "How many boolean variables?? ";
- cin >> n;
- boolean_truth_table(n);
- cout << "total count: " << cnt << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement