National Science and Mathematics Olympiad (NSMO) – Cities and Provinces Test: Informatics 1 (Juniors): free practice test

Start with 10 free questions to see what needs more practice. Finish to see your score, weakest units and every option explained.

Back to National Science and Mathematics Olympiad (NSMO) – Cities and Provinces Test: Informatics 1 (Juniors)

Practice test questions with answers and explanations

Try the questions in the test above first, then open each one here to see the correct answer and why every other option is wrong.

01Which of the following is NOT a valid constant declaration?

Past exam question Unit: C++ Basics: Variables, Types and Operators

  1. Aconst char first_letter = 'a';

    A char constant can be initialised with a char literal like 'a'.

  2. Bconst double N = 10;

    The int literal 10 converts to double, so this declaration is valid.

  3. Cconst int SIX = 7;

    A constant name need not match the value; SIX = 7 is valid.

  4. Dconst double THREE = "3.000"; ✓ Correct answer

    "3.000" is a string literal, not a number, so it cannot initialise a double.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 2; official answer key (mawhiba.sa)

02What is the value of x after the following code is executed?

Past exam question Unit: C++ Basics: Variables, Types and Operators

int x = 6;
x++;
x *= 3;
--x;
x /= 4;
  1. A4

    This skips x++ and mishandles the operations; the trace ends at 5.

  2. B5 ✓ Correct answer

    6 -> 7 -> 21 -> 20 -> 20/4 = 5, following each statement in order.

  3. C20

    The code continues past x *= 3 and --x, then divides by 4.

  4. D7

    This stops after x++, but --x and x /= 4 still change x.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 4; official answer key (mawhiba.sa)

03What will be printed after executing the following code?

Past exam question Unit: Conditions

if ((15 % 4 > 3) || (27 % 11 == 6)) {
    cout << "first";
} else {
    cout << "second";
}
  1. Asecond ✓ Correct answer

    15 % 4 = 3, so 3 > 3 is false; 27 % 11 = 5, so the else branch prints second.

  2. Bfirstsecond

    Only one branch runs in if...else, so both words cannot print.

  3. Cnothing is printed

    A false condition does not skip the else branch; it prints second.

  4. Dfirst

    This treats 15 % 4 or 27 % 11 incorrectly; both conditions are false.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 5; official answer key (mawhiba.sa)

04What is the value of n after the following code is executed?

Past exam question Unit: Loops

int n = 0;
for (int i = 3; i < 10; i++) {
    n += i;
}
  1. A52

    Includes 10, but the condition i < 10 stops at 9, so the sum is 42.

  2. B39

    Starts at 4 instead of 3; the code begins with i = 3, giving 42.

  3. C42 ✓ Correct answer

    The loop adds 3+4+...+9, so n becomes 42 after all iterations.

  4. D45

    Sums from 0, but n starts at 0 and the loop adds 3 through 9, giving 42.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 10; official answer key (mawhiba.sa)

05What is the value of k after the following code is executed?

Past exam question Unit: Loops

int n = 20;
int k = 0;
while (n > 0) {
    n -= k++;
}
  1. A8

    One extra step is added, but the loop stops after n becomes -1, so k is 7.

  2. B7 ✓ Correct answer

    n takes 20,19,17,14,10,5,-1 while k becomes 1..7, so k ends at 7.

  3. C5

    Uses ++k mentally; the code uses k++, so the subtraction sequence makes k end at 7.

  4. D6

    Stops when n reaches 5, but the condition is n > 0, so one more step makes k = 7.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 11; official answer key (mawhiba.sa)

06What is the value of n after the following code is executed?

Past exam question Unit: Loops

int n = 478;
while (n > 100){
    n -= n % 11;
    n -= 4;
}
  1. A84

    Does one extra pass: 95 → 88 → 84, but the loop stops because 95 > 100 is false.

  2. B95 ✓ Correct answer

    Each pass rounds n down to a multiple of 11, then subtracts 4; 106 → 99 → 95, then stops.

  3. C99

    Stops right after n -= n % 11 in the last pass; the code still subtracts 4, giving 95.

  4. D106

    Stops at the first value near 100, but 106 > 100 keeps the loop going until 95.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 17; official answer key (mawhiba.sa)

07How many different outputs can the function f return over all possible values of i?

Past exam question Unit: Functions and Recursion

int f(int i) {
    int j = (i > 0 ? i : -i);
    return (j % 2) * (j % 3) * (j % 4);
}
  1. A12

    Assumes one per residue mod 12, but the actual outputs are only 0,1,2,3,6.

  2. B4

    Forgets 0; the function can return 0 as well as 1,2,3,6, making 5 values.

  3. C5 ✓ Correct answer

    The outputs are 0,1,2,3,6, so there are 5 different values in total.

  4. D6

    Counts j%4=2 cases, but the distinct outputs listed are 0,1,2,3,6, which is 5.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 16; official answer key (mawhiba.sa)

08What is the result of calling rec(261074)?

Past exam question Unit: Functions and Recursion

int rec(int x){
    if (x == 0) return 0;
    if (x % 10 == 0) return rec(x / 10);
    return 1 + rec(x - 1);
}
  1. A21

    Adds 1 for the zero digit; a trailing 0 is only removed by x / 10, which adds nothing, so the total stays 20.

  2. B18

    Loses 2 on the way, for example by counting the leading 2 as 0; every nonzero digit d adds exactly d, so 2+6+1+7+4 = 20.

  3. C6

    Counts the digits of 261074, but rec adds 1 for every unit subtracted, so it returns the digit sum 20.

  4. D20 ✓ Correct answer

    Each nonzero last digit is counted down by x - 1, adding 1 per step; trailing zeros are dropped free. Total 2+6+1+0+7+4 = 20.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 18; official answer key (mawhiba.sa)

09What is the value of count after the following code is executed?

Past exam question Unit: Arrays, Vectors, Strings and Simulation

int m[5][5] = {
    {1, 1, 0, 1, 0},
    {1, 1, 1, 1, 1},
    {0, 1, 1, 1, 0},
    {1, 1, 1, 1, 1},
    {1, 1, 0, 1, 1}
};
int count = 0;
for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
        if (m[i][j] && m[i][j + 1] && m[i + 1][j] && m[i + 1][j + 1]) {
            count++;
        }
    }
}
  1. A6

    Misses one block; the trace says exactly 7 of the tested 2x2 blocks contain only 1s.

  2. B7 ✓ Correct answer

    The loops test all 16 top-left corners, and exactly 7 of the 2x2 blocks are all 1s.

  3. C9

    Counts all 9 blocks whose corner is in the middle 3x3 area; the code checks 16 corners and only 7 blocks are all 1s.

  4. D8

    Counts a block that contains a 0; only 7 of the 16 checked blocks satisfy the condition.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 14; official answer key (mawhiba.sa)

10What is the value of steps after the following code is executed?

Past exam question Unit: Arrays, Vectors, Strings and Simulation

char b[][7] = {
    {'#', '#', '#', '#', '#', '#', '#'},
    {'#', '.', '.', '#', '.', '.', '#'},
    {'#', '#', '.', '.', '.', '#', '#'},
    {'#', '.', '#', '.', '.', '.', '#'},
    {'#', '.', '.', '.', '#', '#', '#'},
    {'#', 'o', '.', '.', '.', '.', '#'},
    {'#', '#', '#', '#', '#', '#', '#'}
};
int pi = 3;
int pj = 3;
int di = -1;
int dj = 0;
int steps = 0;
while (b[pi][pj] != 'o') {
    if (b[pi + di][pj + dj] != '#') {
        pi += di;
        pj += dj;
        steps++;
    } else {
        int di_ = di;
        di = -dj;
        dj = di_;
    }
}
  1. A17

    Misses the final move onto o; the loop counts that last move too, so steps becomes 18.

  2. B13

    Counts only turns, but steps++ happens on each move; the walker moves 18 times to o.

  3. C18 ✓ Correct answer

    Starting at row 3 col 3, the walker makes 18 moves before reaching o, while turns do not add to steps.

  4. D31

    Adds the 13 turns to the 18 moves; only actual moves increment steps, so the value is 18.

Reference: Mawhiba NSMO 2026 Stage 1, Informatics 1 (Juniors) paper, question 19; official answer key (mawhiba.sa)

NSMO Informatics 1

Full prep for this exam

All of this in one purchase.

  • Full mock exam, same as the real one20 questions in 120 minutes. You get a total score and a score for every unit.
  • Practice unit by unit510 questions, every option explained with its source. Starts with your weakest units.
  • Complete Review Guide 2026–2027 (PDF)Ordered by each unit's weight in the exam. With lifetime access only.

Choose your access

One step before payment

Continue with your Google account and you go straight to the payment page.

Check my score freeFull prep