#include <iostream> using namespace std; void InsertionSort(int a[], int n) { for(int i = 1; i < n; ++i) { int key = a[i]; int j = i-1; while(j >= 0 && key < a[j]) { a[j+1] = a[j]; --j; } a[j+1] = key; } } int main() { int n; cin >> n; int a[n]; for(int i = 0; i < n; ++i) { cin >> a[i]; a[i] *= a[i]; } InsertionSort(a, n); for(int i = 0; i < n; ++i) { cout << a[i] << " "; } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter