Advertisement
constk

Lab6_Task3_BubbleSort

Nov 27th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "stdio.h"
  3. #include <iostream>
  4.  
  5. int main() {
  6. setlocale(0, "Russian");
  7.  
  8. const int N = 5;
  9. short A[N];
  10.  
  11. for (int i = 0; i < N; i++) {
  12. printf("A[%d] = ", i);
  13. scanf("%hd", &A[i]);
  14. }
  15. puts("");
  16.  
  17. for (int i = 0; i < N; i++) {
  18. for (int j = 0; j < N - 1; j++) {
  19. if (A[j] > A[j + 1]) {
  20. short t = A[j];
  21. A[j] = A[j + 1];
  22. A[j + 1] = t;
  23. }
  24. }
  25. }
  26.  
  27. for (int i = 0; i < N; i++) {
  28. printf("A[%d] = %hd\n", i, A[i]);
  29. }
  30.  
  31. system("pause");
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement