SHARE
TWEET

Untitled

a guest Oct 21st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <locale.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7. #define SIZE 50
  8. int main()
  9. {
  10. srand(time(NULL));
  11. setlocale(LC_ALL, "rus");
  12. int n, i, j, min_i, temp;
  13. puts("Введите натуральное число n, меньшее 50");
  14. scanf_s("%d", &n);
  15. if (n >= 50 || n <= 0)
  16. {
  17. puts("условие не выполнено");
  18. return(0);
  19. }
  20. signed int a[SIZE];
  21. printf_s("Созданный массив \n");
  22. for (int i = 0; i < n; i++)// заполняем массив и выводим его
  23. {
  24. a[i] = rand() % 100 - 20;
  25. printf_s("%d ", a[i]);
  26. }
  27. printf_s("\n");
  28. printf_s("Отсортированный массив \n");
  29. for (int i = 0; i < n - 1; i++)
  30. {
  31. int min_i = i;
  32. for (int j = i + 1; j < n; j++)
  33. {
  34. if (a[j] < a[min_i])
  35. {
  36. min_i = j;
  37. }
  38. }
  39. int temp = a[i];
  40. a[i] = a[min_i];
  41. a[min_i] = temp;
  42. }
  43. for (int i = 0; i < n; i++)
  44. {
  45. printf_s("%d ", a[i]);
  46. }
  47. return 0;
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top