Input
Output
#include <iostream> using namespace std; int main() { int a[100] ={2,1,8,3,7}, n = 5, i, j, temp; cout << "Enter the number of elements: "; cin << n << endl; cout << "Enter the integers: "; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0 ; i < n - 1; i++) { for (j = 0 ; j < n - i - 1; j++) { if (a[j] > a[j+1]) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } cout << "\nSorted array: "; for (i = 0; i < n; i++) { cout << a[i] << " "; } return 0; }