ChameL1oN

Лаба5_Задача1(Вар.8)

Dec 14th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 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. int* form_massive(int count){
  11. int* massive = new int[count];
  12. int a = 0;
  13. time_t t;
  14. srand((unsigned)time(&t));
  15. while (a < count){
  16. massive[a] = rand()%100;
  17. cout << "massive [" << a << "] = " << massive[a] << endl;
  18. a++;
  19. }
  20. return massive;
  21. }
  22. void init_massive(int massive[], int &count){
  23. int a = 0,i,j=1,n=0;
  24. int k = 0;
  25. if (count % 2 == 0){
  26. while (k < count / 2){
  27. massive[k] = massive[j];
  28. j+=2;
  29. k++;
  30. }
  31.  
  32. }
  33. else{
  34. while (k < count / 2 +1){
  35. massive[k] = massive[j];
  36. j += 2;
  37. k++;
  38. }
  39. }
  40. count -= k;
  41. return;
  42. }
  43. void print_massive(int massive[], int count){
  44. cout << "Массив после обработки" << endl;
  45. for (int i = 0; i <= count - 1; i++){
  46. cout << "massive [" << i << "] = " << massive[i] << endl;
  47. }
  48. }
  49.  
  50. void main(){
  51. int count, k;
  52. setlocale(LC_ALL, "rus");
  53. cout << "Введите кол-во элементов в массиве ";
  54. cin >> count;
  55. int* mas = form_massive(count);
  56. init_massive(mas, count);
  57. print_massive(mas, count);
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment