• Share this text:
Report Abuse
Untitled - posted by guest on 11th March 2020 10:49:45 PM

#include <stdio.h>

#include <time.h>

#include <unistd.h>

#include <stdlib.h>

int main()

{

    long int vet[300000];

    for (int i =0; i<300000; i++){

        vet[i] = rand() % 1000;

        printf("\nGerando numero: %d\n\n", i);

    }

    int max = vet[0];

    int min = vet[0];

 double time_spent = 0.0;

 clock_t begin = clock();

    for (int i=0; i<300000; i++){

            if (vet[i] > max)

                max = vet[i];

             else if (vet[i] < min)

                min = vet[i];

    }

    printf("\nMax: %d\n", max);

    printf("\nMin: %d\n", min);

 clock_t end = clock();

 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;

 printf("Time elpased is %f seconds", time_spent);

 return 0;

}

Report Abuse

Login or Register to edit or copy and save this text. It's free.