 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
A Boolean Array Puzzle in C?
This an array based puzzle that need you to change all the numbers of an array the contains two elements to 0. One element of the array is 0 and other may or may not be 0.
To solve this puzzle the program needs to find the non-zero element and change in to 0.
Their are the following constraints that are needed to solve the boolean array puzzle −
- Allowed operation is complement, other operations are not allowed.
- Loops and conditional statements are not allowed.
- Direct assignment is also not allowed.
PROGRAM TO SOLVE 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; }  Output
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] ]
Advertisements
 