The challenge consist in writing a program that deletes the duplicated values of an array.
#include <iostream>
using namespace std;
void func(int arrayA[], int n, int arrayB[]) {
int h = 0;
int count = 0;
arrayB[0] = arrayA[0];
for (int i = 1; i < n; i++) {
count = 0;
for (int j = 0; j < n; j++) {
if (arrayB[i] == arrayA[j]) {
count++;
}
}
if (count == 0) {
h++;
arrayB[h] = arrayA[i];
}
}
}
int main() {
int n;
cin >> n;
int arrayA[n];
int arrayB[n];
for (int i = 0; i < n; i++) {
cin >> arrayA[i];
}
func(arrayA, n, arrayB);
for (int i = 0; i < n; i++) {
cout << arrayB[i] << endl;
}
}
My logic was creating a new array and filling it with the non repeated values, for that i created a loop that adds 1 to a counter when it finds a repeated value and if the counter is equal to 0 the value is added. then the counter restarts.
Thank you for your help to a new programmer i really tried to solve it in my own.