12,071,956 members (51,965 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 5:41am
Edited 5-May-10 23:10pm
Moak11.5K
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
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

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
 OriginalGriff 365 Dave Kreskowiak 250 F-ES Sitecore 180 Richard MacCutchan 145 Sascha Lefèvre 140
 Dave Kreskowiak 2,426 OriginalGriff 1,949 Richard MacCutchan 1,675 CPallini 1,222 CHill60 1,219