Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <time.h>
- int main() {
- SetConsoleOutputCP(CP_UTF8);
- srand(time(NULL));
- int a[100];
- printf("Наш исходный массив;\n");
- for(int i=0;i<100;i++)
- {
- a[i]=rand()%201-100;
- printf("%d ",a[i]);
- }
- int start=-1,startmax=0,finish=0,s=0,ms=0;
- for (int i = 0; i < 100; ++i) {
- if (a[i]>0)
- {
- s+=a[i];
- if(start==-1)
- {
- start=i;
- }
- }
- else
- {
- if(s>ms)
- {
- ms=s;
- finish=i;
- startmax=start;
- }
- s=0;
- start=-1;
- }
- }
- printf("\nнаибольшая сумма в последовательности:\n");
- for (int i = startmax; i < finish; ++i) {
- printf("%d ",a[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement