13,089,943 members (47,647 online)
Rate this:
See more:
What is the problem in this code?

```#include
using namespace std;

int main ()

{	int const arraysize=10;
int a[arraysize];
int maximum=0;
int minimum=a[0];
int i;

for ( i= 0 , i > (arraysize) , i++ )
{
cin>>a[i];

if (a[i]>=maximum)
maximum=a[i];

if(a[i]<=minimum)
minimum=a[i];

}

cout<<"the maximum of array a is : "<<maximum<<endl;
cout<<"the minimum of array a is : "<<minimum<<endl;

return 0;

}```
Posted 12-Apr-10 4:41am
Updated 5-May-10 22:10pm
Moak11.6K
v4

Rate this:

## Solution 2

joek1991 wrote:
int maximum=0; int minimum=a[0];

change to
```int maximum = INT_MIN;
int minimum = INT_MAX;```

joek1991 wrote:
for ( i= 0 , i > (arraysize) , i++ )

change to
`for ( i = 0 ; i < arraysize ; i++ )`

(IMHO a good `C/C++` tutorial would help)
:)
Rate this:

## Solution 3

IMO, you would have pinpointed this problem in 1 minute, by using the debugger and single-step your program.
Learning how to use the debugger is well worth the time spent.
Rate this:

## Solution 1

You are declaring minimum as a value a[0] before assigning a value to a[0].
Rate this:

## Solution 4

hi,

first initialize the value of a[0]

a[0]=0;

second

for ( i= 0 ;i < (arraysize);i++ )

hope now u can run ur programme.
Rate this:

## Solution 7

I think so. Loop //for ( i= 0 , i > (arraysize) , i++ ) not has a end point. in fact, this willn't be excuted because conditions is not true
Rate this:

## Solution 8

very simple answer is to look at the loop and change > to <
i < arraysize
Rate this:

## Solution 5

OMG Look at the accepted answer :doh:
He didnt event point the actual problem in for loop check expression. and there is nothing wrong with setting junk/default value to minimum as it will get updated in loop.
Rate this:

## Solution 6

Y u ppl recommending to hardcore values of minimum and maximum to 0 and let it use as it is for checks?
Think what if minimum value set to 0 and actual minimum value in array is 1 :doh:

your actual code should be like this

```#include
using namespace std;

int main ()

{	int const arraysize=10;
int a[arraysize];
int maximum=0;
int minimum=0;
int i;

for ( i= 0 , i > (arraysize) , i++ )
{
cin>>a[i];

if (a[i]>=maximum || i==0)
maximum=a[i];

if(a[i]<=minimum || i==0)
minimum=a[i];
}

cout<<"the maximum of array a is : "<<maximum<<endl;
cout<<"the minimum of array a is : "<<minimum<<endl;

return 0;

}```

Top Experts
Last 24hrsThis month
 ProgramFOX 250 Richard Deeming 220 Graeme_Grant 150 OriginalGriff 150 ppolymorphe 120
 OriginalGriff 3,412 Graeme_Grant 1,874 ProgramFOX 1,707 Jochen Arndt 1,645 ppolymorphe 1,507