Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main()
- {
- int a[1000000];
- int maxTop = 0;
- int top = 0;
- int bas, son;
- int lenght = sizeof(a)/sizeof(a[0]);
- int i=0;
- int j=0;
- clock_t a1,b1;
- srand(time(NULL));
- a1 = clock();
- for (j=0; j<=lenght-1; j++ ){
- top = top + a[j];
- if(top > maxTop){
- maxTop = top;
- bas = i;
- son = j;
- }
- else if(top < 0){
- i = j+1;
- top = 0;
- }
- }
- b1 = clock();
- printf("Algoritma %.18f saniyede tamamladi.",(double)(b1-a1)/CLOCKS_PER_SEC);
- printf("Sonuc: %d",maxTop);
- return maxTop;
- }
- //100.000 elemanlı dizi yaklaşık olarak 0.00000 saniye sürmektedir.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement