Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C_141211_OrdenarArrayConFunciones
//Title of this code #include <stdio.h> #include <stdlib.h> #include <time.h> #define _T 10000 void asignarAArrayValoresAleatorios(long dim , long a[dim], long x1, long x2); void mostrarArrayPorPantalla(long dim, long a[dim]); void ordenarArrayMenorMayor(long dim, long a[dim]); long valorMayorArray(long dim, long a[dim]); long valorMenorArray(long dim, long a[dim]); void intercambiarValores(long*a, long*b); int main(void) { long array[_T]; long intervaloMenor, intervaloMayor; printf("Intervalo menor: "); scanf(" %ld", &intervaloMenor); printf("Intervalo mayor: "); scanf(" %ld", &intervaloMayor); if(intervaloMenor > intervaloMayor) { intercambiarValores(&intervaloMenor, &intervaloMayor); } asignarAArrayValoresAleatorios(_T, array, intervaloMenor, intervaloMayor); mostrarArrayPorPantalla(_T, array); printf("\n\n\tEl mayor valor del array es: %ld\n", valorMayorArray(_T, array)); printf("\n\n\tEl menor valor del array es: %ld\n", valorMenorArray(_T, array)); ordenarArrayMenorMayor(_T, array); mostrarArrayPorPantalla(_T, array); return 0; } void asignarAArrayValoresAleatorios (long dim , long a[dim], long x1, long x2) { srand(time(NULL)); long i; for(i = 0 ; i < dim ; i++) { a[i] = x1 + rand() % (x2 - x1 + 1); } return; } void mostrarArrayPorPantalla(long dim, long a[dim]) { long i; for(i = 0 ; i < dim ; i++) { if(i % 6 == 0) { printf("\n"); } printf("%8ld", a[i]); } return; } void ordenarArrayMenorMayor(long dim, long a[dim]) { long i, j; for(i = 0 ; i < dim ; i++) { for(j = i + 1 ; j < dim ; j++) { if(a[i] > a[j]) { intercambiarValores(a + i, a + j); } } } return; } long valorMayorArray(long dim, long a[dim]) { long i, mayor; for(mayor = a[0], i = 1 ; i < dim ; i++) { if(mayor < a[i]) { mayor = a[i]; } } return mayor; } long valorMenorArray(long dim, long a[dim]) { long i, menor; for(menor = a[0], i = 1 ; i < dim ; i++) { if(menor > a[i]) { menor = a[i]; } } return menor; } void intercambiarValores(long*a, long*b) { *a ^= *b; *b ^= *a; *a ^= *b; return; }
run
|
edit
|
history
|
help
0
Programação em C, testes
18BCE2182 ASSESS_2 Q1
Project 5 v.05
Score
pseudo hw
lab9tho
test
B_141212_RolloPunteros
Lab6 v1.2 Sin,cos,tan,cot
141128_EjemploChorraArray