Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int *x, *poc, k, n, s = 0, smax = 0, br;
- do
- {
- printf("Unesite n: ");
- scanf("%d", &n);
- }while(n < 1 || n > 40);
- x = (int*) malloc (n * sizeof(int));
- for(poc = x ; poc < x + n ; poc++) *poc = 0;
- do
- {
- printf("Unesite k: ");
- scanf("%d", &k);
- }while(k < 1 || k > n);
- printf("\nUNOS NIZA\n\n");
- for(poc = x ; poc < x + n ; poc++)
- {
- printf("X[%d] = ", poc - x);
- scanf("%d", poc);
- }
- for(poc = x + 1 ; poc < x + n ; poc++)
- {
- if(*poc * *(poc - 1) > 0)
- {
- if(s == 0) s = *(poc - 1);
- br++;
- s += *poc;
- }
- else if(br >= k && (smax == 0 || s > smax)) smax = s, br = 1, s = 0;
- else br = 1, s = 0;
- }
- if(br >= k) smax = s;
- printf("\n\nSmax = %d\n\n",smax);
- free(x);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement