I'm trying to make a code that drop down the lowest 2 or 3 numbers in an array. here is my code can someone help fixing it. Thank you
#include<stdio.h>
#include<math.h>
#include<assert.h>
int main() {
const int MAXSIZE = 5;
int d开发者_C百科roptop[MAXSIZE] = { 17, 18, 16, 15,16 };
int drop = 2;//the amount of grades need to be dropped
int dtstore[MAXSIZE];//the array I want the new grade to be stored in
int j = 0;
int compare = droptop[0];//assigned int compare to be the first num of the array so it looks at the rest of the loop
while (j < drop) {
for (int i = 0; i < 6; i++) {
if (compare > droptop[i] || compare != dtstore[i]) {
compare = droptop[i];
dtstore[i] = compare;
}
}
j++;
}
}
I tried to make a loop inside a loop that look over all the array and compare it with the first number. what I mean by the first number is the first number of the array "int compare = droptop[0];". I made the while loop to be the amount of number wanting to drop if the amount done it stops. hopefully someone can help, and my goal to store the new array after the lowest grades are dropped in a different array and the the lowest grades in a different array.
精彩评论