Answer the question
In order to leave comments, you need to log in
What is wrong with selection sort?
I don’t see an error, it doesn’t write anything when compiling, I run it and it just hangs
#include <stdio.h>
int main()
{
int array[n];
int i, j;
int temp;
int min;
printf("vvedite n: \n");
scanf ("%d", &n);
for(i = 0; i < n; i++)
{
printf("vvedite massiv: \n");
scanf("%d", &array[i]);
}
for (i = 0; i < n - 1; i++)
{
min = i;
for (int j = i + 1; j < n; j++)
{
if (array[j] < array[min])
{
min = j;
}
}
temp = array[i];
array[i] = array[min];
array[min] = temp;
}
for (i = 0; i < n; i++)
{
printf ("%d ", array[i]);
}
}
Answer the question
In order to leave comments, you need to log in
when compiling it says nothing...
Here are some questions for you to think about:
- where is the variable n defined in this program?
- what does the construct doint array[n]
if n is a variable?
- how is the allocation of memory forint array[n]
and the input of the value n through scanf related?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question