Thursday, 26 June 2014

C++ program to copy one array to another


Here is a C++ program to copy one array to another


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int a1[20],a2[20],num;
    cout<<"How many elements to be stored (max 20) : ";
    cin>>num;
    cout<<"Enter elements of array a1 : ";
    for(int i=0;i<num;i++)
        cin>>a1[i];
    for(int i=0;i<num;i++)
        a2[i]=a1[i];
    cout<<"After copy arrays a2 : ";
    for(int i=0;i<num;i++)
        cout<<a2[i]<<" ";
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment