Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <conio.h>
- #include <iostream>
- using namespace System;
- using namespace std;
- void GenerarArreglo(int *arr, int n)
- {
- Random r;
- for (int i = 0; i < n; i++)
- {
- arr[i] = r.Next(1, 51);
- }
- }
- void ImprimirArreglo(int *arr, int &n)
- {
- for (int i = 0; i < n; i++)
- {
- cout << arr[i] << endl;
- }
- }
- void EliminaMult(int *arr, int n)
- {
- int cont=0, cont2=0;
- for (int i = 0; i < n; i++)
- {
- if (arr[i] % 3 == 0)
- cont++;
- }
- int *temp = new int[n - cont];
- for (int i = 0; i < n; i++)
- {
- if (arr[i] % 3 != 0)
- {
- temp[i-cont2] = arr[i];
- }
- else cont2++;
- }
- if (arr != NULL)
- delete[]arr;
- arr = temp;
- n = n - cont;
- cout << endl;
- ImprimirArreglo(arr, n);
- }
- int main()
- {
- int n;
- cout << "Ingrese n: "<<endl;
- cin >> n;
- cout << endl;
- int *arreglo = new int[n];
- GenerarArreglo(arreglo, n);
- ImprimirArreglo(arreglo, n);
- EliminaMult(arreglo, n);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment