/* vectmsum.c Dado um vetor com números positivos e negativos aleatoriamente distribuidos, obtenha um subvetor de elementos consecutivos cuja soma seja maxima - MC404B - Out 2001 */ #include #define TMAX 16 #define RANGE 128 void rand8(char tab[], unsigned int size) /* generate random integers between -RANGE,+RANGE */ { unsigned int i; int sum; srand(time()); /*comment this line to always get the same sequence */ printf("\nGenerating %d random signed integers:\n",size); for (i=0; i maxsum){ maxsum=csum; start= i; end=j; }else if (csum < 0){ i= j+1; csum=0; } } printf("\nsubvector with largest sum:\n start end sum\n"); printf("%6d %6d %6d\n",start,end,maxsum); }