200: Find and print all unique elements of a given array of integers
// Find and print all unique elements of a given array of integers
#include <iostream>
using namespace std;
int main()
{
int size;
cout << "Enter the size of array: ";
cin >> size;
int array[size];
for (int i = 0; i < size; i++)
{
cout << "Enter a string for index " << i << ": ";
cin >> array[i];
}
system("cls");
cout << "All unique elements of array are: ";
for (int i = 0; i < size; i++)
{
int count = 0;
for (int j = 0; j < i; j++)
{
if (array[i] == array[j])
{
count++;
}
}
if (count == 0)
{
cout << array[i] << ' ';
}
}
return 0;
}
Comments
Post a Comment