Created
January 11, 2015 18:17
-
-
Save xmpf/9e540c77f4cc10e486a3 to your computer and use it in GitHub Desktop.
ECE[@]NTUA: Σειρά 7 Άσκηση 23 (maxsum) - Εισαγωγή στον Προγραμματισμό Η/Υ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Σωστός, δεν είχα δει την εκφώνηση.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ψάχνει για το μέγιστο άθροισμα διαδοχικών όρων ακολουθίας.