Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale>
- #include <fstream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- // Удалить элементы с чётными номерами
- int* form_massive(int count){
- int* massive = new int[count];
- int a = 0;
- time_t t;
- srand((unsigned)time(&t));
- while (a < count){
- massive[a] = rand()%100;
- cout << "massive [" << a << "] = " << massive[a] << endl;
- a++;
- }
- return massive;
- }
- void init_massive(int massive[], int &count){
- int a = 0,i,j=1,n=0;
- int k = 0;
- if (count % 2 == 0){
- while (k < count / 2){
- massive[k] = massive[j];
- j+=2;
- k++;
- }
- }
- else{
- while (k < count / 2 +1){
- massive[k] = massive[j];
- j += 2;
- k++;
- }
- }
- count -= k;
- return;
- }
- void print_massive(int massive[], int count){
- cout << "Массив после обработки" << endl;
- for (int i = 0; i <= count - 1; i++){
- cout << "massive [" << i << "] = " << massive[i] << endl;
- }
- }
- void main(){
- int count, k;
- setlocale(LC_ALL, "rus");
- cout << "Введите кол-во элементов в массиве ";
- cin >> count;
- int* mas = form_massive(count);
- init_massive(mas, count);
- print_massive(mas, count);
- }
Advertisement
Add Comment
Please, Sign In to add comment