Advertisement
damch

dsd

Dec 14th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. static int max=0;
  5. int podniza(int a[],int n,int m){
  6. int i;
  7. int j=m;
  8. int suma=0;
  9. if(n==-1)
  10. return max;
  11. else
  12. {
  13. if(m<=n)
  14. for(i=n;j>0;i--,j--)
  15. suma=suma+a[i];
  16.  
  17.  
  18. if(suma>max)
  19. max=suma;
  20.  
  21. return podniza(a,n-1,m);
  22. }
  23. }
  24. int main()
  25. {
  26. int n;
  27. int m;
  28. scanf("%d %d",&n,&m);
  29. int a[n];
  30. int i;
  31.  
  32. for(i=0;i<n;i++)
  33. scanf("%d",&a[i]);
  34.  
  35. printf("%d",podniza(a,n-1,m));
  36.  
  37.  
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement