/** * This is a short quiz to see whether or not you understand arrays. * * General notes: * %d : a placeholder when displaying integer values using printf(). * * \n : displays a new line * * _array_size(array_name) : returns the size, or number of elements, * in the array called 'array_name'. * * my_variable++ : increments the value of a variable by 1 and is the same as * my_variable = my_variable + 1; * * my_variable-- : decrements the value of a variable by 1 and is the same as * : my_variable = my_variable - 1; */ void main(){ // declare and initialize our variables int index = 0; int c = 0; int t = 0; int grades[] = {24, 65, 82, 99, 10, 19}; // What is the lowest index of an array? // If we let n be the number of elements in an array, // what is the highest index of the array? // How many elements are in the array called 'grades'? for(index = 0; index < _array_size(grades); index++){ if( grades[index] > 65 ){ c = c + 1; } } // What will print to the screen in the following statement? printf("c: %d\n", c); for(index = 0; index < _array_size(grades); index++){ t = t + grades[index]; } // What will print to the screen in the following statement? printf("t: %d\n", t); // Extra Credit! t = 0; c = 0; for(index = 0; index < _array_size(grades); index++){ if( (grades[index] > 40) && (grades[index] < 90) ){ t = t + grades[index]; c = c + 1; } } // What will print to the screen in the following statement? printf("t: %d, c: %d\n", t, c); }