UNKNOWN //************************************** // Name: output elements in array without repitition // Description:you give in an array with repeating elements and get all the elements in the array without repitition // By: Thejwal P // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //This code is copyrighted and has limited warranties. //Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.13832/lngWId.3/qx/vb/scripts/ShowCode.htm //for details. //************************************** #include<iostream.h> #include<stdio.h> void count(int input1[],int); int main() { int size; cout<<endl<<"ENTER SIZE OF ARRAY"; cin>>size; int input[size]; cout<<endl<<"ENTER ELEMENTS OF AN ARRAY TO LIST THE NUMBERS IN IT WITHOUT REPITITION"<<endl; for(int i=0;i<size;i++) cin>>input[i]; count(input,size); } void count(int input[],int size) { int record[size],j; //note:record array keeps a record of the elements encounterd //for(int i=0;i<size;i++) //record[i]=0; int match=0; int i,d,index=0; for(i=0;i<size;i++) //take the elements in input array one by one for comparing with record array { //cout<<endl<<"input["<<i<<"]="<<input[i]; match=0; //set flag variable in case the number is already recorded in the record array for(j=0;j<index;j++) { //cout<<endl<<"record["<<j<<"]="<<record[j]; if(input[i]==record[j]) { //cout<<endl<<record[j]; match=1; break; //if match set flag vaiable } } if(match==0) // if no record of the element has been made yet copy it into the record record[index++]=input[i]; //cout<<endl<<"j="<<j; } for(i=0;i<index;i++) cout<<endl<<record[i]; }