1)
#include <iostream>
using namespace std;
int main()
{
const int size = 20;
int M[size];
for (int i = 0; i < size; i++) {
cout << "M[" << i << "] = ";
cin >> M[i];
}
int temp;
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (M[j] > M[j + 1]) {
temp = M[j];
M[j] = M[j + 1];
M[j + 1] = temp;
cout << M[i] << " ";
cout << endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
1)
#include <iostream>
using namespace std;
int main()
{
const int size = 20;
int M[size];
for (int i = 0; i < size; i++) {
cout << "M[" << i << "] = ";
cin >> M[i];
}
int temp;
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (M[j] > M[j + 1]) {
temp = M[j];
M[j] = M[j + 1];
M[j + 1] = temp;
}
}
}
for (int i = 0; i < size; i++) {
cout << M[i] << " ";
}
cout << endl;
return 0;
}