You are on page 1of 1

#include<stdio.

h>

int main()

{
int n, i, j;

float x[100], aux;

printf("n="); scanf("%d", &n); //reading the number of elements from keyboard

for (i = 0; i < n; i++) { //


printf("x[%d]=", i); // reading each element of the vector from keyboard
scanf("%f", &x[i]); //
} //

// from here we start sorting the vector using selection method


for (i = 0; i < n - 1; i++)

for (j = i + 1; j < n; j++)


if (x[i]>x[j]){
aux = x[i];

x[i] = x[j];

x[j] = aux;

}
//from here we display the vector after we sorted it
for (i = 0; i < n; i++)

printf("%6.1f", x[i]);
}

You might also like