
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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] ]
- Related Articles
- A Boolean Array Puzzle In C Program?
- A Product Array Puzzle in C?
- A Product Array Puzzle in C++?
- A Sum Array Puzzle in C++?
- C++ Sum Array Puzzle
- A product array puzzle (O(1) Space) in C++?
- A C Puzzle in C Programming?
- A C/C++ Pointer Puzzle?
- A C/C++ Function Call Puzzle?
- Sliding Puzzle in C++
- A C Programming Language Puzzle?
- A Puzzle using C Program
- C/C++ Pointer Puzzle?
- Verbal Arithmetic Puzzle in C++
- C/C++ Function Call Puzzle?

Advertisements