12.37 Chapter 5 : Put Smallest First
C++
#include <iostream> #include <vector> using namespace std; int main() { vector<int> v; int n; cout << "Enter 10 integers: "; for (int i = 0; i < 10; ++i) { cin >> n; v.push_back(n); } int minIndex = 0; for (int i = 0; i < v.size(); ++i) { if (v[i] < v[minIndex]) minIndex = i; } int temp = v[0]; v[0] = v[minIndex]; v[minIndex] = temp; for (int i = 0; i < v.size(); ++i) { cout << v[i] << " "; } cout << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.