int bottle[9] {1,3,2,5,6,2,3,5,3}; //here bottle[4] would be the largest
I was thinking about making a for loop, and setting 9 different variables to each number,
and changing the variables each time it goes through the loop, is there a better way to do this?
int largestNumber=0;
for(int i=0; i < 9; i++)
{
if(bottle[i] > largestNumber)
largestNumber = bottle[i];
}
There are quicker ways of finding particular values, however you would have to sort the information in some way first.
If you are at the stage where you are having trouble working out how to get the highest value from an array of integers you are not yet ready for more advanced data structures (just in case after reading this you go look into them polyneem, don't be disheartened).
int bottle[9] {1,3,2,5,6,2,3,5,3}; //here bottle[4] would be the largest
I was thinking about making a for loop, and setting 9 different variables to each number,
and changing the variables each time it goes through the loop, is there a better way to do this?
you can use the bubble sort method to find out the maximum number fro array. i
this method is very simple and easy to use.
in this method element element is compare to next element of array.
consider part of code,
int MAX = 0;
for(i= 0 ;i<=9;i++)
{
if (bottle >MAX)
MAX = bottle;
}
int bottle[9] {1,3,2,5,6,2,3,5,3}; //here bottle[4] would be the largest
I was thinking about making a for loop, and setting 9 different variables to each number,
and changing the variables each time it goes through the loop, is there a better way to do this?
you can use the bubble sort method to find out the maximum number fro array. i
this method is very simple and easy to use.
in this method element element is compare to next element of array.
consider part of code,
int MAX = 0;
for(i= 0 ;i<=9;i++)
{
if (bottle >MAX)
MAX = bottle;
}
printf(Largest Number : %d",MAX);
getch();
congratulations on 2 things. First, you have managed to reiterate what was said at least once before (just in a slightly different way), and you also have been able to necro a 5-month old thread. Though 5 months isn't that bad, it's still a necro.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Ginto8 wrote:congratulations on 2 things. First, you have managed to reiterate what was said at least once before (just in a slightly different way), and you also have been able to necro a 5-month old thread. Though 5 months isn't that bad, it's still a necro.
Spot on! ... also
MacJordan wrote:
you can use the bubble sort method to find out the maximum number fro array.
That's not bubble sort, that's just a basic linear search. And by method I guess you mean "algorithm".
Ginto8 wrote:congratulations on 2 things. First, you have managed to reiterate what was said at least once before (just in a slightly different way), and you also have been able to necro a 5-month old thread. Though 5 months isn't that bad, it's still a necro.
Spot on! ... also
MacJordan wrote:
you can use the bubble sort method to find out the maximum number fro array.
That's not bubble sort, that's just a basic linear search. And by method I guess you mean "algorithm".
Omg, did he really did just say that? Any post that is a 5 month necro and has the phrase "bubble sort" in it should warrant a punch in the face for ignorance.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!