Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <locale.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4.  
  5. int main()
  6. {
  7. setlocale(LC_ALL, "rus");
  8. int n;
  9. printf("Введите кол-во элементов массива n > 0: ");
  10. scanf("%d", &n);
  11.  
  12. if (n > 0)
  13. {
  14. int* arr = new int[n];
  15. printf("\nПоочередно введите сами элементы массива: ");
  16. for (int i = 0; i < n; i++)
  17. scanf("%d", &arr[i]);
  18.  
  19. int t = 0;
  20. for (int i = 0; i < n - 1; i++)
  21. for (int j = i + 1; j < n; j++)
  22. if (arr[i] > arr[j])
  23. {
  24. t = arr[i];
  25. arr[i] = arr[j];
  26. arr[j] = arr[i];
  27. }
  28.  
  29. for (int i = 0; i < n; i++)
  30. printf("%d ", arr[i]);
  31.  
  32. }
  33. else
  34. printf("Вы ввели отрицательные значения");
  35. getch();
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement