Ask Question
13 August, 02:53

Hi guys

I have a vector with 9 elements

vec[20] = 80.59, 132.40, 81.85, 79.83, 119.96, 111.89, 110.99, 101.21, 118.53

Im trying to put them in an anscending order

thats what the console shows me:

80.59 79.83 81.85 101.21 110.99 111.89 118.53 119.96 132.40

for (k=1; k<=i-1; k++)

{

for (j=k+1; j {

if (vec[k]>vec[j])

{

aux=vec[k];

vec[k]=vec[j];

vec[j]=aux;

}

}

}

Up is the formule i used but it is not working.

What Should I do? I am working in C Programming.

+5
Answers (1)
  1. 13 August, 04:50
    0
    Vectors and arrays are 0-based, so they don't start at 1 but at 0

    your sort works by switching positions of 2 elements, which in your case didn't happen for the pair of the first&second element

    your outer-loop starts with k=1, which should be k=0 instead
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Hi guys I have a vector with 9 elements vec[20] = 80.59, 132.40, 81.85, 79.83, 119.96, 111.89, 110.99, 101.21, 118.53 Im trying to put them ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers