#include <stdio.h> #include <time.h> #include <stdlib.h> int main(int argc, char** argv) { int *hs; int i,j, testes, vertices; int novo, cont=0; int hMax; if(argc<3) { printf("Use resp2 tamanho testes\n"); return 0; } srand(time(NULL)); vertices = atoi(argv[1]); hs = malloc(vertices*(sizeof*hs)); testes = atoi(argv[2]); for(i=0;i<testes;i++) { hs[0]=0; hMax = 0; for(j=1;j<vertices;j++) { novo = rand()%j; hs[j]=hs[novo]+1; if(hs[j]>hMax) hMax = hs[j]; } cont+=hMax; } printf("altura media %f\n",(float) ((float)cont)/((float)testes)); return 0; }