Skip to content

Instantly share code, notes, and snippets.

@VitorDiToro
Created September 20, 2016 13:14
Show Gist options
  • Save VitorDiToro/3534c4752c018dd7ed85d28017230e35 to your computer and use it in GitHub Desktop.
Save VitorDiToro/3534c4752c018dd7ed85d28017230e35 to your computer and use it in GitHub Desktop.
Maior soma de uma subsequencia (Apenas a soma)
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int aux = 0, soma = 0;
int i;
int vet[] = {-2,-3,4,-1,-2,1,5,-3};
int n = sizeof(vet)/sizeof(int);
for(i=0; i<n; i++)
{
aux = (aux + vet[i])>0 ? aux+vet[i] : aux;
soma = aux>soma ? aux : soma;
}
printf(" Soma = %i\n",soma);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment