Tech Study

Write C++ program to copy all elements of one array to another

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.

#include <iostream>
#define MAX_SIZE 100 //Maximum size of the array
using namespace std;
 
int main()
{
    int first[MAX_SIZE], second[MAX_SIZE];
    int i, num;
 
    //Enter size of array
    cout<<"Enter the size of the array : ";
    cin>>num;
 
    //Reading elements of array
    cout<<"Enter elements of first array : ";
    for(i=0; i<num; i++)
    {
        cin>>first[i];
    }
 
 
   //Copy all elements from first array to second array
   for(i=0; i<num; i++)
    {
        second[i] = first[i];
    }
 
    //Printing all elements of first array entered by user
    cout<<"Elements of first array are:"<<endl;
    for(i=0; i<num; i++)
    {
        cout<<first[i]<<"\t";
    }
 
 
    //Printing all elements of second array
   cout<<"\nElements of second array are: \n ";
                                for(i=0; i<num; i++)
    {
         cout<<second[i]<<"\t";
    }
 
  return 0;
}

Result

Write C++ program to copy all elements of one array to another
Write C++ program to copy all elements of one array to another

TaggedWrite C program to copy all elements of one array to another

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more