greetings,I'm trying to make a program which finds the smallest number in an array of numbers yet everytime when I run the program the result I get(number that is returned) is 1 all the time even if i don't enter 1 in the values 1 will still be returned,
Well it looks like PBachmann already answered it for you. He changed the function definition as well, so if you are in some way supposed to use that third parameter you will need to explain in more detail.
Using constint size = 10; allows you to not need as many parameters for your function, but also makes your function less robust. It is up to you to decide which is more useful.
Thanks guys from what I hear it's called the insertion sort algorithm unfortuantly Alex Allain didn't really explain it in detail in his book I really need to have a look over PBachmann's code and study it =) thanks guys
Hey adam2016, that makes a lot more sense now! The assignment is asking you to sort your array via the insertion sort algorithm, so studying PBachmann's answer is not going to be too useful to you. While he/she are wrote what we thought you were trying to do correctly, we now know you are actually trying to implement something else.
I would study how insertion sort works, and then try implementing it.
None in particular sorry! However I do suggest you look up "visualize insertion sort" and look at some of the visual animations of what is going on in the insertion sort. When I was learning about insertion sort, actually seeing the array change was what made it click.
int main ()
{
int nr , smallest , v[101] , i ; // nr = number of numbers you have in that array
cin>>nr; // v[] = is the array ;
for(i=1;i<=nr;i++)
cin>>v[i];
smallest = v[1]; //first , smallest will be the first position , than you
for(i=2;i<=nr;i++) //compare the whole array with it to check if there
if( v[i] < smallest ) // are smaller numbers
smallest = v[i];
cout << smallest;
return 0; }