Week 05 Tutorial Questions

Arrays Practice

This week, we will discuss arrays, and complete a program to practice writing arrays.

Diagram of an array

Tutor Demo! (10 mins)

We have been provided the following program that intends to do the following steps but has some flaws.

Flowchart of activity

// part1_arrays.c, odd_only
//
// Written by YOUR-NAME (YOUR-ZID)
// on TODAYS-DATE 
//
// This program adds 1 to any odd element in an array and after prints 
// all elements in the array

#include <stdio.h>

#define SIZE 5

int main(void) {

    int array = {1, 2, 3, 4, 5};

    int i = 0;
    while (i < SIZE) {
        if (array.i % 2 == 0) {
            array.i += 1;
        }
    }

    int j = 1;
    while (j < SIZE) {
        printf("%c ", array.j);
    }

    printf("\n");

    return 0;
}

We will go through and debug the program so it executes as expected.

Your turn!

Copy Array

Voice of the Student

✨ Help Us Improve Your Learning Experience ✨

Your feedback helps us understand what’s working well and what might need improvement. This quick, anonymous check-in has just two questions and takes less than a minute to complete.

Please answer honestly — your input makes a real difference.