Created
June 16, 2013 06:49
-
-
Save elit69/5791130 to your computer and use it in GitHub Desktop.
array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
bool search(int a[],int n,int num) | |
{ for(int i=0; i<n; i++) { | |
if(a[i] == num) { | |
return true; | |
} | |
} | |
return false; | |
} | |
int main(void) | |
{ int a[] = {5,3,8,7,9,4,9,8,6,5564,56,45,64,56,456,45,6,4565,56,4363,46,3,4,68,23,245,64,56,5}; | |
int n = sizeof(a)/sizeof(int); | |
int b[50]={0}; //this | |
int counter = 0; | |
for(int i=0; i<n; i++) { | |
for(int j=0; j<n; j++) { | |
if(a[i] == a[j] && i != j) { | |
if(!search(b, n, a[j])) { | |
b[counter] = a[j]; | |
counter++; | |
} | |
} | |
} | |
} | |
cout << "counter\t" << counter << endl; | |
for(int i=0; i<counter; i++) | |
cout<<b[i]<<endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
bool search(int a[],int n,int num) | |
{ for(int i=0; i<n; i++) { | |
if(a[i] == num) { | |
return true; | |
} | |
} | |
return false; | |
} | |
int main(void) | |
{ | |
int a[] = {7,1,2,3,4,5,6}; | |
int b[] = {2,2,3,4,2,2,8,9}; | |
int c[10] = {0}; | |
int nc = 0; | |
int d[10] = {0}; | |
int nd = 0; | |
int na = sizeof(a)/sizeof(int); | |
int nb = sizeof(b)/sizeof(int); | |
// | |
for(int i=0; i<na; i++) { | |
if( search(b,nb,a[i]) && !search(c,nc,a[i])) { | |
c[nc] = a[i]; | |
nc++; | |
} | |
} | |
// | |
for(int i=0; i<na; i++) { | |
if(!search(c,nc,a[i])) { | |
d[nd] = a[i]; | |
nd++; | |
} | |
} | |
for(int i=0; i<nb; i++) { | |
if(!search(c,nc,b[i])) { | |
d[nd] = b[i]; | |
nd++; | |
} | |
} | |
// | |
cout<<"array c"<<endl; | |
for(int i=0; i<nc; i++) { | |
cout << c[i] << endl; | |
} | |
cout<<"array d"<<endl; | |
for(int i=0; i<nd; i++) { | |
cout << d[i] << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment