Ask Question
23 July, 23: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. 24 July, 00:48
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers