If we have an array of Interger values, find out a sub array
which has a maximum value of the array and start and end
positions of the array..The sub array must be contiguious.
Take the start add to be 4000.

For Ex if we have an array arr[] =
{-1,-2,-5,9,4,3,-6,8,7,6,5,-3}

here the sub array of max would be
{8,7,6,5} coz the sum of max contiguous array is 8+7+6+5 =
26.The start and end position is 4014(8) and 4020(5).

Answer Posted / sowmya

# include<stdio.h>
int main()
{
int i,j,k,sum[30],l,z =0,num = 0,sub,len;
int a[30],index[15][15],temp;
sum[z] = 0;
printf("\n Enter the Max.no. of elements to be
entered in the array :\n");
scanf("%d",&len);
printf("\n Enter the array Values : \n");
for(i=0;i<len;i++)
scanf("%d",&a[i]);
for(i = 0;i <len;i++)
{
k = len/2;
l = i+k;
for(j=i;j<l;j++)
if(j<len)
{
num++;
}
if(num == k)
{
for(j =i;j<l;j++)
{
if(j<len)
sum[z] = sum[z]+a[j];
else printf("\n num <3!");
}
z++;
sum[z] = 0;
}
num = 0;
}
j = 0;
for(i = 0 ;i <z;i++)
{
printf(" sum[%d] = %d\n",i,sum[i]);
index[j][i] = sum[i];
}
for(i = 0;i<z;i++)
{
for(j = i+1;j<z;j++)
if(sum[i] < sum[j])
{
temp = sum[i];
sum[i] = sum[j];
sum[j] = temp;
}
}
j= 0;
for(i = 0;i<z;i++)
if(index[j][i] == sum[0])
sub = i;
printf(" Sub array of max. sum = { ");
for(i = sub;i<sub+k;i++)
printf(" %d ",a[i]);
printf("}");
return 0;

}

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

620


List the different types of c tokens?

629


What are the advantages of using macro in c language?

596


Which header file is essential for using strcmp function?

947


List the difference between a While & Do While loops?

641






What are the types of type specifiers?

625


How can I invoke another program (a standalone executable, or an operating system command) from within a c program?

656


Hi can anyone tell what is a start up code?

1618


What are the types of variables in c?

582


What is the benefit of using const for declaring constants?

592


How will you find a duplicate number in a array without negating the nos ?

1650


What is the function of this pointer?

678


find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }

1863


What does it mean when the linker says that _end is undefined?

638


What are the uses of null pointers?

594