Created
April 7, 2017 07:46
-
-
Save RicardoLara/9a85c5025b890f98b8ca01168fed36f9 to your computer and use it in GitHub Desktop.
Práctica 3 4/5[AA] - Daniel Cruz García. ¡CON TRAMPA!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "tiempo.h" | |
int Maxim(int * A, int n); | |
int Maximo(int * A, int ini, int fin, int max){ | |
return Maxim(A,fin); | |
int max_aux = 0; | |
if (ini == fin) max = A[ini]; | |
else{ | |
int mitad = (ini+fin)/2; | |
Maximo(A,ini,mitad,max); | |
Maximo(A,mitad+1,fin,max_aux); | |
if(max_aux > max) max = max_aux; | |
} | |
return max; | |
} | |
int main(){ | |
double utime0, stime0, wtime0,utime1, stime1, wtime1; | |
int j, n = 0; | |
for(j=0; j<50; j++){ | |
n += 20000; | |
printf("\n------------------- NUMERO %d --------------------- \n",j+1); | |
int k,A[n],s; k=0; | |
FILE *fp = fopen("./DatosAleatorios2.txt","r"); | |
fscanf(fp,"%d",&s); | |
while(k<n){ | |
A[k] = s; | |
fscanf(fp,"%d",&s); k++; | |
} | |
fclose(fp); | |
uswtime(&utime0, &stime0, &wtime0); // Medicion Mode: ON! :v | |
printf("El maximo de los %d datos analizados es: %d\n",n,Maximo(A,0,n,0)); | |
uswtime(&utime1, &stime1, &wtime1); | |
//Cálculo del tiempo de ejecución del programa | |
printf("\n"); | |
printf("real (Tiempo total) %.10f s\n", wtime1 - wtime0); | |
} | |
return 0; | |
} | |
int Maxim(int * A, int n){ | |
int k=0; int maxy = 0; | |
while(k<n){ | |
if(A[k] > maxy) maxy = A[k]; | |
k++; | |
} | |
return maxy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment