Assignment 5 Solutions
Assignment 5 Solutions
#include <stdio.h>
#define SIZE 7
int main(void) {
int data[] = { 5, 3, -12, 34, 2, -17, 6 };
int index = 0;
int maxVal = data[0];
index = 0 1 ..6
while (index < SIZE) {
if (data[index] > maxVal){ index=0, maxVal = 5
maxVal = data[index]; index=1,
...
} index=3, maxVal = 34
index++; ...
}
return 0;
}
Q2.
int data[] = { 5, 3, -12, 34, 2, -17, 6 };
return NOT_FOUND;
}
Q3.
#define NOT_FOUND -1
return duplicates_found;
}
Q4. index = 0,1,2..size-1 (index<size)
index = startIndex, startIndex+1... size-1
return indexOfMin;
}
12345678
col_i=0
row_i=0 1 2 3 4 arr
row_i=1 5 6 7 8 arr[0][0]
Q5.
rowIndex这一行小于threshold这个值的元素的数量
int belowThresholdOnRow(int data[][NUMCOLS], int rowIndex, int
threshold){
int count = 0;
for (int colIndex = 0; colIndex < NUMCOLS; colIndex++) {
if (data[rowIndex][colIndex] < threshold){
count++;
}
}
return count;
}
Q6.