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...

You're given an array containing both positive and negative
integers and required to find the sub-array with the largest
sum (O(N) a la KBL). Write a routine in C for the above.

Answer Posted / sujan

#include<iostream>
#define SIZE 16
using namespace std;
int main()
{
int a[SIZE] = {-3, 5, -9, 4, -6, -24, -13, -14, -3, -20,
-45, -11, -2, -8, 1,10};
int temp[SIZE];
int j=0,sum=0;
for(int i=0;i<=SIZE;i++)
{
if(a[i]>0)
{
temp[j]=a[i];

j++;
}

}
cout<<"Sub-array:";
for(int k=0;k<j-1;k++)
{
sum+=temp[k];
cout<<temp[k]<<"\t";
}


cout<<"\n"<<"Sum:"<<sum<<endl;


system("pause");
}

Is This Answer Correct ?    3 Yes 31 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a breakpoint?

975


What is c++ coding?

1146


Define whitespace in C++.

1157


Is c++ slower than c?

998


How do you print a string on the printer?

1006


Which is the best c++ software?

1056


Can you Mention some Application of C/C++?

1023


Define the process of handling in case of destructor failure?

1021


How to access a variable of the structure?

1032


What is setbase c++?

1069


How to declaring variables in c++?

1123


Is c++ proprietary?

1024


What programming language should I learn first?

1054


What do you mean by ‘void’ return type?

1011


Explain what are mutator methods in c++?

1082