Swap the two Arrays entered

23:48 0 Comments A+ a-

Problem:
Define a function swapArrays(…) that takes two arrays and their size as parameters, and swaps the contents of the two arrays. Call this function through main().
Solution:
# include <iostream>
using namespace std;
void swapArrays(int a[],int b[],int size);
int main()
{
const int size=10;
int array1[size];
int array2[size];
swapArrays(array1,array2,size);

return 0;
}
void swapArrays(int a[],int b[],int size)
{
cout<<"Please enter the "<<size<<" elements of Array 1"<<endl;
for(int i=0;i<size;i++)
{
cin>>a[i];
}
cout<<"Please enter the "<<size<<" elements of Array 2"<<endl;
for(int i=0;i<size;i++)
{
cin>>b[i];
}
for(int i=0;i<size;i++)
{
int temp=a[i];
a[i]=b[i];
b[i]=temp;
}
cout<<"Array 1 after swaping becomes"<<endl;
for(int i=0;i<size;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
cout<<"Array 2 after swaping becomes"<<endl;
for(int i=0;i<size;i++)
{
cout<<b[i]<<" ";
}
cout<<endl;

}