ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint8_t x = 250;
    int n = 0;
    do {
        x += 3;
        n++;
    } while (x != 4);
    printf("%d", n);
}
  1. A. 86
  2. B. 171
  3. C. 175
  4. D. 174

Correct answer: D. 174

Each step adds 3 modulo 256, so we need 3k = 10 mod 256 starting from 250. The solution k = 174 uses 3 inverse 171 modulo 256.

More C Programming questions

Exams that ask this topic