Skip to content

Instantly share code, notes, and snippets.

@RicardoLara
Created February 20, 2017 02:06
Show Gist options
  • Select an option

  • Save RicardoLara/21c017997a3fe785ce02944919e43de5 to your computer and use it in GitHub Desktop.

Select an option

Save RicardoLara/21c017997a3fe785ce02944919e43de5 to your computer and use it in GitHub Desktop.
Práctica 1 1/5[AA] - Daniel Cruz García
#include<stdio.h>
#include "tiempo.h"
int Producto2Mayores(int * A, int n){
int i,mayor1,mayor2;
if(A[1] > A[2]) {
mayor1 = A[1];
mayor2 = A[2];
}
else{
mayor1 = A[2];
mayor2 = A[1];
}
i = 3;
while(i<=n){
if(A[i] > mayor1){
mayor2 = mayor1;
mayor1 = A[i];
}
else if(A[i] > mayor2)
mayor2 = A[i];
i++;
}
return mayor1*mayor2;
}
int main(){
double utime0, stime0, wtime0,utime1, stime1, wtime1; //Variables para medición de tiempos
int i,n;
int A[] = {3,2,3,5,7,1,3,2,3,5,7,1,3,2,3,5,7,11,3,2,3,5,7,1,3,2,31,3,2,3,5,7,1,3,2,3,1,3,2,3,5,7,1,3,2,3,1,3,2,3,5,7,1,3,2,3,1,3,2,3,5,7,1,3,2,31,3,2,3,5,7,1,3,2,31,3,2,3,5,7,1,3,2,3,1,3,2,3,5,7,1,3,2,3};
for(i=0; i<50; i++){
n = i+3;
printf("------------------- NUMERO %d --------------------- \n",i+1);
uswtime(&utime0, &stime0, &wtime0);
printf("Resultado: %d\n",Producto2Mayores(A,n));
uswtime(&utime1, &stime1, &wtime1);
//Cálculo del tiempo de ejecución del programa
printf("\n");
printf("real (Tiempo total) %.10f s\n", wtime1 - wtime0);
printf("user (Tiempo de procesamiento en CPU) %.10f s\n", utime1 - utime0);
printf("sys (Tiempo en acciónes de E/S) %.10f s\n", stime1 - stime0);
printf("CPU/Wall %.10f %% \n",100.0 * (utime1 - utime0 + stime1 - stime0) / (wtime1 - wtime0));
printf("\n");
//Mostrar los tiempos en formato exponecial
printf("\n");
printf("real (Tiempo total) %.10e s\n", wtime1 - wtime0);
printf("user (Tiempo de procesamiento en CPU) %.10e s\n", utime1 - utime0);
printf("sys (Tiempo en acciónes de E/S) %.10e s\n", stime1 - stime0);
printf("CPU/Wall %.10f %% \n",100.0 * (utime1 - utime0 + stime1 - stime0) / (wtime1 - wtime0));
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment