task4.cpp 519 B

123456789101112131415161718192021222324252627
  1. #include <iostream>
  2. int main() {
  3. int arr[] = {12, 11, 13, 5, 6};
  4. int n = sizeof(arr) / sizeof(arr[0]);
  5. for (int i = 1; i < n; i++) {
  6. int key = arr[i];
  7. int j = i - 1;
  8. while (j >= 0 && arr[j] > key) {
  9. arr[j + 1] = arr[j];
  10. j--;
  11. }
  12. arr[j + 1] = key;
  13. }
  14. std::cout << "Отсортированный массив: ";
  15. for (int i = 0; i < n; i++) {
  16. std::cout << arr[i] << " ";
  17. }
  18. std::cout << std::endl;
  19. return 0;
  20. }