This is an array-based puzzle that requires you to change all the numbers in an array containing two elements to 0. One element of the array is 0, and another element may or may not be 0.
To solve this puzzle, the program needs to find the non-zero element and change it to 0.
The following are the constraints required to solve the Boolean array puzzle −
#include <iostream> using namespace std; void makeZero(int a[2]) { a[ a[1] ] = a[ !a[1] ]; } int main() { int a[] = {1, 0}; makeZero(a); cout<<"arr[0] = "<<a[0]<<endl; cout<<"arr[1] = "<<a[1]; return 0; }
arr[0] = 0 arr[1] = 0 You can use other ways too. Like this one which does not require the negation operation. a[ a[1] ] = a[ a[0] ]
The above is the detailed content of Boolean array puzzle in C language. For more information, please follow other related articles on the PHP Chinese website!