#include #include #include void makerandary(int*, int); int main(int argc, char *argv[]){ int sizeofaray, i; int *aray; int topstart, topend, max, temp; int tempstart, tempend; sizeofaray = atoi(argv[1]); aray = (int*)malloc(sizeof(int) * sizeofaray); makerandary(aray, sizeofaray); for(i = 0;i < sizeofaray;i++){ printf("%d, ", aray[i]); } printf("\n"); topstart = 0; topend = 0; max = -100; temp = 0; tempstart = 0; tempend = 0; /* °æ°è°ªÀ¸·Î »ç¿ëÇÒ ÀÚ·á´Â À½¼ö°¡ µÇ°Ú°í ±× ÀÌÀü±îÁö´Â °è¼Ó ´õÇØ°£´Ù. ¶ÇÇÑ ¸¶Áö¸· À妽ºÀÏ °æ¿ìµµ È®ÀÎÀ» Çؾ߰ڴÙ. */ for(i = 0; i < sizeofaray;i++){ if(aray[i] > 0){ temp += aray[i]; tempend = i; } if((aray[i] <= 0) || (i == (sizeofaray -1)) ) { if((topstart != tempend) && (temp > max)){ topstart = tempstart; topend = tempend; max = temp; temp = 0; }else{ tempstart = i + 1; tempend = tempstart; temp = 0; } } } printf("index [%d, %d] , value : %d\n", topstart, topend, max); free(aray); return 0; } /* ·£´ýÇÑ ¹è¿­À» ¸¸µç´Ù. */ void makerandary(int *aray, int num){ int i; int j; srand(time(0)); /* À½¼öµµ ÇÊ¿äÇÏ´Ù±¸... */ for(i = 0; i < num;i++){ j = rand() % 100; if((rand() % 2)) aray[i] = j - (2*j); else aray[i] = j; } }