Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<stdlib.h>
- int main()
- {
- int a[] = {1,5,-3,4,-2,1};
- //{1,2,-5,4,7,-2} = 11
- //{1,5,-3,4,-2,1} = 7
- //{-2,11,-4,13,-5,2} = 20
- int maxTop = 0;
- int top = 0;
- int bas, son;
- int lenght = sizeof(a)/sizeof(a[0]);
- int i=0;
- int j=0;
- 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;
- }
- }
- printf("Sonuc: %d",maxTop);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement