4 Replies - 2131 Views - Last Post: 09 October 2009 - 09:36 PM Rate Topic: -----

#1 bunx14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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--";

	 cout<<"\n--the element of your list.--";

	 cout<<"\nEnter your list size: ";

	 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;

}


ModEdit: added code tags: :code:

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+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 bunx14  Icon User is offline

  • New D.I.C Head

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

Re: Largest/Smallest Numbers in Array

Posted 09 October 2009 - 09:27 PM

View PostseeP+, 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?
Was This Post Helpful? 0
  • +
  • -

#4 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • 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];.
Was This Post Helpful? 0
  • +
  • -

#5 bunx14  Icon User is offline

  • New D.I.C Head

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

Re: Largest/Smallest Numbers in Array

Posted 09 October 2009 - 09:36 PM

View PostseeP+, 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!!!:D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1