Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
B_141212_OrdenarArray
//Title of this code #include <stdio.h> #include <stdlib.h> #include <time.h> #define _T 100 void mostrarArray(long tam , short a[tam]); void rellenarAleatoriosArray (long tam, short a[tam], short lI, short lS); void ordenarValoresArray(long tam , short a[tam]); void intercambiar(short*x, short*y); double calculoMediaValoresArray(long tam, short a[tam]); int main(void) { short array[_T]; rellenarAleatoriosArray(_T, array, 1000, 2000); mostrarArray(_T, array); printf("\n\n"); ordenarValoresArray(_T, array); mostrarArray(_T, array); double media = calculoMediaValoresArray(_T, array); printf("\n\tLa media es %.2lf\n\n", media); return 0; } void mostrarArray(long tam , short a[tam]) { long i; for(i = 0 ; i < tam ; i++) { if(i % 5 == 0) printf("\n"); printf("%8hd", a[i]); } return; } void rellenarAleatoriosArray (long tam, short a[tam], short lI, short lS) { long i; for(srand(time(NULL)), i = 0 ; i < tam ; i++) { a[i] = lI + rand() % (lS - lI + 1); } return; } void ordenarValoresArray(long tam , short a[tam]) { long i, j; for(i = 0 ; i < tam ; i++) { for(j = i + 1 ; j < tam ; j++) { if(a[i] > a[j]) { intercambiar(a + i, &a[j]); } } } return; } void intercambiar(short*x, short*y) { short aux = *x; *x = *y; *y = aux; return; } double calculoMediaValoresArray(long tam, short a[tam]) { double suma; long i; for(suma = i = 0 ; i < tam ; i++) { suma += a[i]; } return suma / tam; }
run
|
edit
|
history
|
help
0
EXercice
SAI_1-3.c
lab pro v.05
Calculating longs p v1
11
B_141125_Burbuja
ponyerb orange panther
Basic String Compression in C
printing float pointers
Primes in binary