0% found this document useful (0 votes)
4 views1 page

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)
4 views1 page

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy