include <iostream>
using namespace std;
int
s1[100],s2[100],c[200], i, j, k,m, n;
int main()
{
cout << "dati dimensiunea
primului vector n=" << endl;
cin>>n;
cout<<"Dati elementele primului
vector ordonate crescator";
for(i=1;i<=n;i++)
{
cout<<"s1["<<i<<"]=";
cin>>s1[i];
}
cout << "dati dimensiunea celui de-al doilea vector m="
<< endl;
cin>>m;
cout<<"Dati elementele celui de-al doilea vector ordonate
crescator";
for(i=1;i<=m;i++)
{
cout<<"s2["<<i<<"]=";
cin>>s2[i];
}
i=1;
j=1;
k=1;
while((i<=n)&&(j<=m))
{
if (s1[i]==s2[j])
{ c[k]=s1[i];
i=i+1;}
else
{
if(s1[i]<s2[j]){
c[k]=s1[i];
i=i+1;
}
else {c[k]=s2[j];
j=j+1;
}
}
k=k+1;
}
while(i<=n)
{
c[k]=s1[i];
i=i+1;
k=k+1;
}
while(j<=m){
c[k]=s2[j];
j=j+1;
k=k+1;
}
for(i=1;i<=k;i++)
{
cout<<c[i]<<" ";
}
return 0;
}
Niciun comentariu:
Trimiteți un comentariu