Skip to content

Instantly share code, notes, and snippets.

@DIEGOHORVATTI
Last active May 19, 2022 12:32
Show Gist options
  • Save DIEGOHORVATTI/e84391eb6a9322ccbe2f6184f8cad367 to your computer and use it in GitHub Desktop.
Save DIEGOHORVATTI/e84391eb6a9322ccbe2f6184f8cad367 to your computer and use it in GitHub Desktop.
Verificar tempo de execução de programa em C
#include <stdio.h>
#include <time.h> //clock(), CLOCKS_PER_SEC e clock_t
int main(void){
printf(" %s", "Ler 3 valores e escrevê-los em ordem crescente.\n\n");
int maior, menor, piloto=3, notas[piloto], cache_maior=0;
maior=menor=0;
for (int i=1; i <= piloto; i++){
printf(" Digite um valor[%d]: ", i);
scanf("%d", &notas[i]);
if(notas[i] > maior){
maior=notas[i];
}
if(notas[i] < maior){
menor=notas[i];
}
if (i == 3){
printf("\n Maior valor é %d\n", maior);
printf("\n Menor valor é %d\n", menor);
}
}
// Cabeçalho de teste de execução
clock_t t; //variável para armazenar tempo
t = clock(); //armazena tempo
t = clock() - t; //tempo final - tempo inicial
printf("\n Tempo de execução: %lf", ((double)t)/((CLOCKS_PER_SEC/1000)));
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment