Skip to content

Instantly share code, notes, and snippets.

@xmpf
Created January 11, 2015 18:17
Show Gist options
  • Save xmpf/9e540c77f4cc10e486a3 to your computer and use it in GitHub Desktop.
Save xmpf/9e540c77f4cc10e486a3 to your computer and use it in GitHub Desktop.
ECE[@]NTUA: Σειρά 7 Άσκηση 23 (maxsum) - Εισαγωγή στον Προγραμματισμό Η/Υ
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int N;
int i;
int *a;
int sum;
scanf ("%d", &N);
a = (int *)malloc ((N + 1) * sizeof (int));
if (a == NULL) {
return -1;
}
a[0] = 0;
sum = 0;
for (i = 1; i <= N; i++) {
scanf ("%d", &a[i]);
sum += a[i];
if (sum < 0) {
sum = 0;
}
else
if (a[0] < sum)
a[0] = sum;
}
printf ("%d\n", a[0]);
free (a);
a = NULL;
return 0;
}
@xmpf
Copy link
Author

xmpf commented Jan 11, 2015

Ψάχνει για το μέγιστο άθροισμα διαδοχικών όρων ακολουθίας.

@VHarisop
Copy link

Σωστός, δεν είχα δει την εκφώνηση.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment