Answer to Question #12505 in C# for Nora

Question #12505
Write the C function void kappa_min(int K) that reads from stdin a sequence of integers, of undefined length, terminated by the appearance of the value 0 (zero). The function finds and prints the K smallest integers read (in increasing order).
1
Expert's answer
2012-08-07T07:18:59-0400
void kappa_min(int k){
char byte[256];
int mass[10000] , ind = 0;
while(!feof(stdin)){
& fgets(byte,256,stdin);
& int number = atoi(byte);
& if (number == 0) break;
& mass[ind++] = number;
}

for (int j = 0 ; j < ind ; j++)
for (int i = 0 ; i < ind - 1 ; i++){
& if (mass[i] > mass[i+1]) {
& int temp = mass[i];
& mass[i] = mass[i+1];
& mass[i+1] = temp;
& }
}
for (int i = 0 ; i < k ; i++)
& printf("%i\n",mass[i]);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS