Advertisement
argentinapb

Untitled

Aug 25th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <windows.h>
  7.  
  8. #define MAX 1000
  9.  
  10. int maior(int *vet){
  11. int aux;
  12. int i;
  13. aux = vet[0];
  14. for(i = 0; i < MAX; i++){
  15. if(aux < vet[i]){
  16. aux = vet[i];
  17. }
  18. }
  19. return aux;
  20. }
  21.  
  22. int criar(int n){
  23. int x;
  24. x = rand () % n;
  25. return x;
  26. }
  27.  
  28.  
  29. int main(){
  30. int i = 0;
  31. int n = 1000;
  32. int vet[MAX];
  33. char p;
  34.  
  35.  
  36. FILE *f;
  37. // f = fopen("maior3.txt","a");
  38.  
  39.  
  40.  
  41. // for(int i = 0; i < MAX; i++){
  42. // fprintf(f,"%d ",criar (n));
  43.  
  44. // }
  45. i = 0;
  46. f = fopen("maior3.txt","r");
  47.  
  48. while (!feof(f))
  49. {
  50. fscanf(f,"%d",&vet[i]);
  51. i++;
  52. }
  53. LARGE_INTEGER freq;
  54. LARGE_INTEGER t1,t2;
  55. double tempo;
  56.  
  57. QueryPerformanceFrequency(&freq);
  58. QueryPerformanceCounter(&t1);
  59.  
  60. int x;
  61. x = maior(&vet);
  62. printf("\no maior eh: %d ", x);
  63. QueryPerformanceCounter(&t2);
  64. tempo = (t2.QuadPart-t1.QuadPart)*1000.0/freq.QuadPart;
  65. printf("Tempo de execucao = %lf\n",tempo);
  66.  
  67. fclose(f);
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement