Hi guys,I am new here...So, I'm programming for about 6-7 months,I learnt the usual and the basic stuff and right now I'm on objects stuff.Anyway,I have some problems with thinking how to write the program sometimes,I need a little help with:
So,I have a program which returns the minim number from a vector,easy enough.But I want to see also on which position it is the minim number.For example we got:
a[0]=20
a[1]=19
a[2]=1
so,the programs returns 1 because it is the lowest number,and I want the program to show me also a[2] like an adress..
Here's the cod guys.
btw,in cout it is romanian language:)) it means The minim from the vector is :

 ``1234567891011121314151617181920`` ``````#include using namespace std; int main () { int n,i,j,a[100]; int min; cout<<"n="; cin>>n; for(i=0;i<=n;i++) { cout<<"a["<>a[i]; } min=a[0]; for(i=1;i<=n;i++) { if (min>a[i]) min=a[i]; } cout<<"Minimul din vector este : "<
Last edited on
unsigned int min_index = 0;
...
if (min>a[i])
{
min=a[i];
min_index = i;
}

... cout << ... << min_index << ...

Last edited on
It works only for particular cases...not for all..anyway thanks
Jonin's suggestion seems pretty sound to me. Could you provide an example of the test case for which it fails.
For example if we got ten n's, the lowest number is on the eight vector but the min index shows on the ten vector and so one,just try it on your own :D
jonnin's code looks fine to me also.