Write a C++ program to find the second smallest number and its position in an integer array. (Note, the length of an array and elements in the array should be determined by using cin).
what i did is the following but i think i'm wrong and it only gives the second smallest number but not the position. and i didn't use cin. how do i find it. here is what i got.
printf("Enter the size of the array: ");
printf("Enter %d elements in to the array: ", size);
i put it on c++ and got 2 errors. one is
error C3861 clrscr()
error C2065 undeclared identifier
and after debugging it only gives the second smallest number which i got already in my code but i wanna show the position too. that's why i asked the question.
cout << "Enter the number of elements in your array:\n";
cin >> numElements;
cout << "Enter the numbers in the array:\n";
for (int i=0; i<numElements; i++)
cin >> nValue;
for (int i=0; i<elements.size(); i++)
if (elements[i]<min) min=elements[i];
cout << "The second-smallest value was " << min2 << " and it was found at element " << min2pos << endl;
I know i'm going against what I just said with my system() call.