<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="category">
    <category><text>$course$/top/CodeLab Starter/C Pointers and Unit Tests</text></category>
  </question>
  <question type="codelab">
    <name><text>01. Sum of N integers</text></name>
    <questiontext format="html"><text><![CDATA[<p>Read an integer <code>n</code> followed by <code>n</code> integers and print their sum.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>c</language>
    <template>#include &lt;stdio.h&gt;

int main(void)
{
    return 0;
}
</template>
    <solution>#include &lt;stdio.h&gt;

int main(void)
{
    int n, x, sum = 0;
    scanf("%d", &amp;n);
    for (int i = 0; i &lt; n; i++) {
        scanf("%d", &amp;x);
        sum += x;
    }
    printf("%d\n", sum);
    return 0;
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"4\n10 20 30 40\n","expected":"100\n","code":"","hidden":false,"weight":1},{"stdin":"3\n-5 5 2\n","expected":"2\n","code":"","hidden":false,"weight":1},{"stdin":"0\n","expected":"0\n","code":"","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>02. Power function (test code)</text></name>
    <questiontext format="html"><text><![CDATA[<p>Write <code>int power(int b, int e)</code> returning <code>b</code> raised to the power <code>e</code> (<code>e &ge; 0</code>). Do not write <code>main</code>.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>c</language>
    <template>int power(int b, int e)
{
    return 1;
}
</template>
    <solution>int power(int b, int e)
{
    int r = 1;
    for (int i = 0; i &lt; e; i++) {
        r *= b;
    }
    return r;
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"1024\n","code":"printf(\"%d\\n\", power(2, 10));","hidden":false,"weight":1},{"stdin":"","expected":"81\n","code":"printf(\"%d\\n\", power(3, 4));","hidden":false,"weight":1},{"stdin":"","expected":"1\n","code":"printf(\"%d\\n\", power(7, 0));","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>03. GCD with unit tests (TEST / ASSERT_EQ)</text></name>
    <questiontext format="html"><text><![CDATA[<p>Write <code>int gcd(int a, int b)</code> returning the greatest common divisor of two positive integers.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>c</language>
    <template>int gcd(int a, int b)
{
    return 1;
}
</template>
    <solution>int gcd(int a, int b)
{
    while (b != 0) {
        int t = a % b;
        a = b;
        b = t;
    }
    return a;
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"","code":"TEST(basic) { ASSERT_EQ(gcd(12, 18), 6); ASSERT_EQ(gcd(100, 25), 25); }","hidden":false,"weight":1},{"stdin":"","expected":"","code":"TEST(coprime) { ASSERT_EQ(gcd(17, 13), 1); }","hidden":false,"weight":1},{"stdin":"","expected":"","code":"TEST(same) { ASSERT_EQ(gcd(42, 42), 42); }","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>04. Swap via pointers (unit tests)</text></name>
    <questiontext format="html"><text><![CDATA[<p>Write <code>void swap_ints(int *a, int *b)</code> that swaps the values pointed to by <code>a</code> and <code>b</code>.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>c</language>
    <template>void swap_ints(int *a, int *b)
{
}
</template>
    <solution>void swap_ints(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"","code":"TEST(basic) { int x = 3, y = 9; swap_ints(&amp;x, &amp;y); ASSERT_EQ(x, 9); ASSERT_EQ(y, 3); }","hidden":false,"weight":1},{"stdin":"","expected":"","code":"TEST(neg) { int x = -5, y = 0; swap_ints(&amp;x, &amp;y); ASSERT_EQ(x, 0); ASSERT_EQ(y, -5); }","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>05. Reverse array in-place (unit tests)</text></name>
    <questiontext format="html"><text><![CDATA[<p>Write <code>void reverse_arr(int *a, int n)</code> that reverses an array of <code>n</code> integers in-place.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>c</language>
    <template>void reverse_arr(int *a, int n)
{
}
</template>
    <solution>void reverse_arr(int *a, int n)
{
    for (int i = 0; i &lt; n / 2; i++) {
        int t = a[i];
        a[i] = a[n - 1 - i];
        a[n - 1 - i] = t;
    }
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"","code":"TEST(odd) { int a[] = {1, 2, 3, 4, 5}; reverse_arr(a, 5); ASSERT_EQ(a[0], 5); ASSERT_EQ(a[2], 3); ASSERT_EQ(a[4], 1); }","hidden":false,"weight":1},{"stdin":"","expected":"","code":"TEST(even) { int a[] = {10, 20}; reverse_arr(a, 2); ASSERT_EQ(a[0], 20); ASSERT_EQ(a[1], 10); }","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>06. Maximum element in array (unit tests)</text></name>
    <questiontext format="html"><text><![CDATA[<p>Write <code>int max_arr(const int *a, int n)</code> returning the largest element in a non-empty array of length <code>n</code>.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>c</language>
    <template>int max_arr(const int *a, int n)
{
    return a[0];
}
</template>
    <solution>int max_arr(const int *a, int n)
{
    int m = a[0];
    for (int i = 1; i &lt; n; i++) {
        if (a[i] &gt; m) {
            m = a[i];
        }
    }
    return m;
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"","code":"TEST(pos) { int a[] = {4, 9, 2, 7}; ASSERT_EQ(max_arr(a, 4), 9); }","hidden":false,"weight":1},{"stdin":"","expected":"","code":"TEST(neg) { int a[] = {-10, -3, -25}; ASSERT_EQ(max_arr(a, 3), -3); }","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>07. String length without strlen (constraints)</text></name>
    <questiontext format="html"><text><![CDATA[<p>Write <code>int my_strlen(const char *s)</code> without calling <code>strlen</code>.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>c</language>
    <template>int my_strlen(const char *s)
{
    return 0;
}
</template>
    <solution>int my_strlen(const char *s)
{
    int n = 0;
    while (s[n] != '\0') {
        n++;
    }
    return n;
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"","code":"TEST(basic) { ASSERT_EQ(my_strlen(\"CodeLab\"), 7); ASSERT_EQ(my_strlen(\"\"), 0); }","hidden":false,"weight":1},{"stdin":"","expected":"","code":"TEST(spaces) { ASSERT_EQ(my_strlen(\"a b c\"), 5); }","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules>{"forbid":["strlen"],"require":[],"penalty":100}</rules>
  </question>
  <question type="codelab">
    <name><text>08. Count even elements in array</text></name>
    <questiontext format="html"><text><![CDATA[<p>Write <code>int count_even(const int *a, int n)</code> returning how many elements of <code>a</code> are even.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>c</language>
    <template>int count_even(const int *a, int n)
{
    return 0;
}
</template>
    <solution>int count_even(const int *a, int n)
{
    int c = 0;
    for (int i = 0; i &lt; n; i++) {
        if (a[i] % 2 == 0) {
            c++;
        }
    }
    return c;
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"","code":"TEST(mixed) { int a[] = {1, 2, 3, 4, 6}; ASSERT_EQ(count_even(a, 5), 3); }","hidden":false,"weight":1},{"stdin":"","expected":"","code":"TEST(none) { int a[] = {1, 3, 5}; ASSERT_EQ(count_even(a, 3), 0); }","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
</quiz>
