Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 / manoj

Another approach

# include<stdio.h>

struct index {
int sum;
int start;
int end;
};

int main()
{
struct index sumidx[30],*tmp;

int i,j,z =0,len;
int a[30];

printf("\n Enter the Number 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 - 1;i++)
{
sumidx[z].sum = a[i];
sumidx[z].start = i;
sumidx[z].end = i;

for(j=i+1;j<len;j++)
if(sumidx[z].sum < (sumidx[z].sum + a[j]))
{
sumidx[z].sum = sumidx[z].sum + a[j];
sumidx[z].start = i;
sumidx[z].end = j;
}
else
break;

z++;
}

tmp = sumidx;

for(i = 0;i<z;i++)
{
if(sumidx[i].start != sumidx[i].end)
if(tmp->sum < sumidx[i].sum)
tmp = sumidx+i;
}
printf("\n sum = %d start = %d end
%d\n",tmp->sum,tmp->start,tmp->end);

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

What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?

1010


What is string concatenation in c?

1040


Explain how do you use a pointer to a function?

1063


What are the differences between new and malloc in C?

1085


How can I prevent another program from modifying part of a file that I am modifying?

1016


What are types of structure?

1072


What is static and auto variables in c?

1030


Explain pointer. What are function pointers in C?

1026


cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration

1063


Which is better between malloc and calloc?

1133


What is d scanf?

1031


Explain what is a program flowchart and explain how does it help in writing a program?

1059


What are linker error?

1047


What are different types of operators?

994


What is non linear data structure in c?

978