# 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).

Expert's answer

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]);

}

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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment