0% found this document useful (0 votes)
3 views

array

Uploaded by

chatgpt202422087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

array

Uploaded by

chatgpt202422087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;

bool compare(int arrayNum[],int arraySize,int element);

int main()
{
const int size=10;
int i=1;
int num[size];
int arrayElement;
int counter=0;

while(i<=10)
{

cin>>arrayElement;
if(i==1) //stores first element in array
num[0]=arrayElement;
//compare new element with stored elements
//if element is not a duplicate store it in array
else if (compare(num,size,arrayElement))
{
counter++;
num[counter]=arrayElement;
}

i++;
}
//displays array elements
for(int k=0;k<=counter;k++)
cout<<num[k]<<endl;

return 0;
}

//compare elements in array

bool compare(int arrayNum[],int arraySize,int element)


{
for(int j=0;j<arraySize;j++)
{
if(arrayNum[j]==element)
return false;
}

return true;
}

You might also like