要解决这个谜题,程序需要找到非零元素并将其更改为0。
以下是解决布尔数组谜题所需的约束条件 −
允许的操作是补集,其他操作不允许。不允许使用循环和条件语句。也不允许直接赋值。解决布尔数组谜题的程序#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] = 0arr[1] = 0you can use other ways too. like this one which does not require the negation operation.a[ a[1] ] = a[ a[0] ]
以上就是在c语言中的布尔数组谜题的详细内容。
