Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 54 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int max (int A[], int n){
  4.     int max=0;
  5.     int somma=0;
  6.     int i;
  7.    
  8.     for(i=0; i<n; i++){
  9.         if(somma >0)
  10.             somma+=A[i];
  11.         else
  12.             somma=A[i];1
  13.        
  14.         if(somma < 0)
  15.             somma=0;
  16.            
  17.             if(somma > max)
  18.                 max=somma;
  19.         }
  20.     return somma;
  21. }
  22. int main(){
  23.     int i;
  24.     int n;
  25.     int *A;
  26.         scanf("%d", &n);
  27.         A=(int*)malloc(n*sizeof(int*));
  28.             for(i=0; i<n; i++){
  29.                 scanf("%d", A+i);
  30.             }  
  31.         printf("%d", max(A,n));
  32.        
  33.     return 0;
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top