AR11
QUESTION DESCRIPTION
Professor Malar has given an array, Asked the Students to find the subarray (containing at least 5 numbers) which has the largest sum.
Mandatory function declaration should be "int maxSum(int a[], int n, int k)"
Professor Malar has given an array, Asked the Students to find the subarray (containing at least 5 numbers) which has the largest sum.
Mandatory function declaration should be "int maxSum(int a[], int n, int k)"
TEST CASE 2
INPUT
INPUT
8
12 15 14 30 4 19 23 10
OUTPUT127
#include <stdio.h>
int maxSum(int a[], int n, int k);
int main() {
int n,a[50],i,k=0,res;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
res=maxSum(a,n,k);
printf("%d",res);
return 0;
}
int maxSum(int a[50],int n,int k)
{
int i;
for(i=0;i<n;i++)
{
if(a[i]>0)
k = k+a[i];
}
return k;
}
Comments
Post a Comment