Wednesday, 14 January 2015

Cpp Program to copy elements from one array to another array


This is a Cpp Program which copies elements from one array to another array.

Here elements of the first array are read one by one and then copied into second array and prints them.

PROGRAM :
#include <iostream>

using namespace std;

int main()
{
     int i,n;

    cout << "\nEnter the no of Elements: \t";
    cin >> n;
    int arr[n],b[n];
    for(i=0;i<n;i++)
    {
        cout << "\nEnter Element " <<  i+1 << ": \t";
        cin >> arr[i];
    }
    cout << "\nOriginal array is :\t";
    for(i=0;i<n;i++)
        cout << arr[i] << "\t";
    for (i = 0; i < n; i++)
      b[i] = arr[i];
      cout << "\nCopied array is :\t";
    for(i=0;i<n;i++)
        cout << b[i] << "\t";
    return 0;
}

OUTPUT : 
Cpp - Copy elements from one array to another

No comments:

Post a Comment