Week 04 Tutorial Questions

Tutorial Overview:

First Hour: Arrays Practice

In this short section, we will discuss arrays, and complete a program to practice writing arrays.

Diagram of an array

Tutor Demo!

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 even 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 == 1) {
            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
Largest Character