ChameL1oN

Лаба5_Задача_1

Dec 7th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale>
  3. #include <fstream>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. //Упорядочить по возрастанию чётные элементы
  10.  
  11. int* form_mas(int count){
  12. int* massive = new int[count];
  13. int a=0;
  14. time_t t;
  15. srand((unsigned)time(&t));
  16. while (a < count){
  17. massive[a] = rand();
  18. cout << "massive [" << a << "] = " << massive[a] << endl;
  19. a++;
  20. }
  21. return massive;
  22. }
  23. void init_mas(int massive[],int count){
  24. int a = 0;
  25. for (int i = 1; i < count; i++){
  26. for (int j = count - 1; j >= i; j--){
  27. while (a < count - 1){
  28. if (massive[j] < massive[j - a] && (massive[j] % 2 == 0) && (massive[j - a] % 2 == 0))
  29. {
  30. int r = massive[j];
  31. massive[j] = massive[j - a];
  32. massive[j - a] = r;
  33. }
  34. a++;
  35. }
  36. a = 0;
  37. }
  38. }
  39. }
  40. void print_mas(int massive[], int count){
  41. cout << "Массив после обработки" << endl;
  42. for (int i = 0; i <= count - 1; i++){
  43. cout << "massive [" << i << "] = " << massive[i] << endl;
  44. }
  45. }
  46.  
  47. void main(){
  48. int num, k;
  49. setlocale(LC_ALL, "rus");
  50. cout << "Введите кол-во элементов в массиве ";
  51. cin >> num;
  52. int* mas = form_mas(num);
  53. init_mas(mas, num);
  54. print_mas(mas, num);
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment