1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
int main( int argc, char* argv[] )
{
int n[] = { 10, 20, 0, 10, 20, 30, 0, 10, 20, 30, 40, 50, 60, 70, 0, 10, 20, 30, 40, 0 };
heaviestCar( n, _countof( n ) );
}
int heaviestCar(int arr[],int elements)
{
int heaviest=0;
int carWeight=0;
int temp=0;
for( int temp = 0; temp < elements; temp++ )
{
carWeight += arr[temp];
if (arr[temp] == 0 )
{
if (carWeight > heaviest)
{
heaviest = carWeight;
carWeight = 0;
}
}
}
return heaviest;
}
| |