Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*D'Ottavi Fabio esercizio 5 esercitazione 2, ordinare un vettore*/
- #include <stdio.h>
- #include <stdlib.h>
- #define N 5
- int main (int argc, char * argv[])
- {
- int vet[N], i, j, min, pos, tmp;
- for (i=0;i<N;i++)
- {
- printf("inserire valore nella posizione %d \n", i);
- scanf("%d", &vet[i]);
- }
- for (j=0;j<N;j++)
- {
- min=vet[j];
- for (i=j;i<N;i++)
- { /*il for parte da j perchè risparmio tempo non*/
- if(min>vet[i]) /*facendo calcolare la parte già ordinata*/
- {
- min=vet[i];
- pos=i;
- }
- }
- tmp=vet[j];
- vet[j]=vet[pos];
- vet[pos]=tmp;
- }
- printf("il vettore ordinato risulta: ");
- for (i=0;i<N;i++)
- {
- printf("%d ", vet[i]);
- }
- exit (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement