ProgrammingHardCompetitive coding (CP)
How many integers from 1 to 64 have their low three bits all clear? Compute with this program.
How many integers from 1 to 64 have their low three bits all clear? Compute with this program.
#include <stdio.h>
int main(void) {
int c = 0;
for (unsigned n = 1; n <= 64; n++)
if ((n & 7u) == 0) c++;
printf("%d", c);
}- A. 7
- B. 9
- C. 8
- D. 16
Correct answer: C. 8
The numbers are the multiples of 8 from 8 to 64, which is eight values.
More C Programming questions
- How many times does the letter g occur in "programming"? The program counts it with a pointer walk. c #include <stdio.h> int main(void) {…
- What is printed? c #include <stdio.h> int main(void) { int x = 10; printf("%d %d", x & -x, x & (x - 1)); }
- What is printed? c #include <stdio.h> int main(void) { int v[] = {3, 9, 4}; int p = v; int s = 0; while (p < v + 3) s += p++ 2…
- What is printed? c #include <stdio.h> int main(void) { printf("%c", 'Z' - 'A' + 'a'); }
- What is printed? c #include <stdio.h> #include <stdlib.h> int nd(int n) { int c = 0; for (int d = 1; d <= n; d++) if (n % d == 0) c++…
- How many binary strings of length 4 have exactly two 1s? The program counts them recursively. What is printed? c #include <stdio.h> int…