Thread: How to drop 2 lowest numbers (grades) in a C program

1. How to drop 2 lowest numbers (grades) in a C program

I am in the middle of writing a program with 2D- arrays. The assignment is calculating the average for 18 students based on their 10 quiz grades. The two lowest grades should be dropped. I am currently only able to drop the lowest grade but not the second lowest. I would copy and paste what i have but school computers are locked from personal use. How would a go about dropping the second lowest grade?

2. I would copy and paste what i have but school computers are locked from personal use.
This is the strictest school I've ever heard of, since no one ever stopped me from bringing a USB key with my homework on it, or something.

Anyway, you could sort based on grade and drop N - 2 and N - 1. If you really must delete them rather than simply ignore them, then you'll have to reallocate the 2d array, since arrays are a fixed size.

3. I'm currently off campus and my computer will not recognize the way i have my program saved on my usb. It doesn't matter if i delete or simply ignore them. I understand your suggestion but my professor hasn't covered bubble sorting for 2d arrays...only 1d.

4. You alredy found and dropped the lowest grade once...just do it again.

5. Well you could actually sort a 2d array, but if that's too difficult to figure out--

make an array with positions in them first:
Code:
int positions[N] = {0, 1, 2, 3, ... N - 1 };
This is what you're going to sort. In other words, you need to arrange it such that position[N - 1] for example will give you the index (by column or by row depending on the arrangement) of the lowest grade, and you ignore that one. To sort positions you only need to change how the comparison and swap is written. It depends on which dimension grades will be in, but you would compare:

Code:
if ( students[x][ positions[y] ] > students[x][ positions[ y+1 ] ] )
And then you don't swap all of students[x] and students[ x+1 ] but positions[y] and positions[ y+1 ].

And then you use the positions array to find out which grades to ignore because it will give you the appropriate index in the unsorted students 2d array.

6. this is what i have for the first drop.

Code:
for (r= 0; r<ROWS; r=r+!){

sum= 0;

small=10;

for(c=1; c<COLS; c= c+1){

sum = sum + q[r][c];

if (q[r][c] < small){

small = q[r][c];

}

}

avg = (sum-small)/ (COLS-1);

}

}

7. Code:
if (q[r][c] < small){

small = q[r][c];

}
else if(q[r][c] < small2){

small2 = q[r][c];

}