#include <iostream>
// function which look for an index of min element
int findMinIndex(int* arr, int N)
{
int min_idx = arr[0];
for (int i = 0; i < N - 1; ++i)
if (arr[i] < arr[min_idx])
min_idx = i;
return min_idx;
}
// function swap two elements
void swap(int *a, int *b)
int tmp = *a;
*a = *b;
*b = tmp;
int main()
int N;
std::cin >> N;
int* arr = new int[N];
try
if (N > 100)
throw "You have entered an impossible size of the array!\n";
catch (...)
std::cout << "Something error!\n";
exit(0);
for (int i = 0; i < N; ++i)
std::cin >> arr[i];
std::cout << "\n";
swap(&arr[0], &arr[findMinIndex(arr, N)]);
std::cout << arr[i] << " ";
return 0;
#include <iostream>
// function which look for an index of min element
int findMinIndex(int* arr, int N)
{
int min_idx = arr[0];
for (int i = 0; i < N - 1; ++i)
if (arr[i] < arr[min_idx])
min_idx = i;
return min_idx;
}
// function swap two elements
void swap(int *a, int *b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
int main()
{
int N;
std::cin >> N;
int* arr = new int[N];
try
{
if (N > 100)
throw "You have entered an impossible size of the array!\n";
}
catch (...)
{
std::cout << "Something error!\n";
exit(0);
}
for (int i = 0; i < N; ++i)
std::cin >> arr[i];
std::cout << "\n";
swap(&arr[0], &arr[findMinIndex(arr, N)]);
for (int i = 0; i < N; ++i)
std::cout << arr[i] << " ";
std::cout << "\n";
return 0;
}