# Largest/Smallest Numbers in Array

Page 1 of 1

## 4 Replies - 2598 Views - Last Post: 09 October 2009 - 09:36 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=131065&amp;s=f9d4f092bdc8fd532f3cb0c6f8861b5a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 bunx14

Reputation: 0
• Posts: 3
• Joined: 09-October 09

# Largest/Smallest Numbers in Array

Posted 09 October 2009 - 09:16 PM

hey, im having difficulty finding the largest and smallest number in an array with inputs given by the user..
below is my code, im stuck with the smallest number and it didnt even turn out right.. nid help please!

```#include  <iostream>

using namespace std;

#define   maxsize   10

int main()

{

int small, temp, i, j, n, list[maxsize];

cout<<"\n--You are prompted to enter your list size.--";

cout<<"\n--Then, for your list size, you are prompted to enter--";

cin>>n;

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

{

cout<<"Enter list's element #"<<i<<"-->";

cin>>list[i];

}

for(i=1; i<n; i++)

{
if(small>list[i])
small=list[i];
}
cout<<"the smallest value in the given array is = "<<small<<endl;
return 0;

}
```

This post has been edited by NickDMax: 10 October 2009 - 12:41 AM

Is This A Good Question/Topic? 0

## Replies To: Largest/Smallest Numbers in Array

### #2 seeP+

Reputation: 55
• Posts: 601
• Joined: 20-July 09

## Re: Largest/Smallest Numbers in Array

Posted 09 October 2009 - 09:21 PM

``` for(i=1; i<n; i++)

{
if(small>list[i])
small=list[i];
}
cout<<"the smallest value in the given array is = "<<small<<endl;
return 0;

}
```

So you not going to compare subscript 0 in the array?
set small to subscript 0.

### #3 bunx14

Reputation: 0
• Posts: 3
• Joined: 09-October 09

## Re: Largest/Smallest Numbers in Array

Posted 09 October 2009 - 09:27 PM

seeP+, on 9 Oct, 2009 - 08:21 PM, said:

``` for(i=1; i<n; i++)

{
if(small>list[i])
small=list[i];
}
cout<<"the smallest value in the given array is = "<<small<<endl;
return 0;

}
```

So you not going to compare subscript 0 in the array?
set small to subscript 0.

im sory im really new to this,
how will i set small to subscript 0?

### #4 seeP+

Reputation: 55
• Posts: 601
• Joined: 20-July 09

## Re: Largest/Smallest Numbers in Array

Posted 09 October 2009 - 09:30 PM

``` for(i=1; i<n; i++)

{
if(small>list[i])
small=list[i];
}
cout<<"the smallest value in the given array is = "<<small<<endl;
return 0;

}
```

Before the if statement in the for loop. Set small = list[0];.

### #5 bunx14

Reputation: 0
• Posts: 3
• Joined: 09-October 09

## Re: Largest/Smallest Numbers in Array

Posted 09 October 2009 - 09:36 PM

seeP+, on 9 Oct, 2009 - 08:30 PM, said:

``` for(i=1; i<n; i++)

{
if(small>list[i])
small=list[i];
}
cout<<"the smallest value in the given array is = "<<small<<endl;
return 0;

}
```

Before the if statement in the for loop. Set small = list[0];.

THANK YOU!!!