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


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


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

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


  1. #include <iostream>
  2. #define MAX_SIZE 100 //Maximum size of the array
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int first[MAX_SIZE], second[MAX_SIZE];
  8. int i, num;
  9.  
  10. //Enter size of array
  11. cout<<"Enter the size of the array : ";
  12. cin>>num;
  13.  
  14. //Reading elements of array
  15. cout<<"Enter elements of first array : ";
  16. for(i=0; i<num; i++)
  17. {
  18. cin>>first[i];
  19. }
  20.  
  21.  
  22. //Copy all elements from first array to second array
  23. for(i=0; i<num; i++)
  24. {
  25. second[i] = first[i];
  26. }
  27.  
  28. //Printing all elements of first array entered by user
  29. cout<<"Elements of first array are:"<<endl;
  30. for(i=0; i<num; i++)
  31. {
  32. cout<<first[i]<<"\t";
  33. }
  34.  
  35.  
  36. //Printing all elements of second array
  37. cout<<"\nElements of second array are: \n ";
  38. for(i=0; i<num; i++)
  39. {
  40. cout<<second[i]<<"\t";
  41. }
  42.  
  43. return 0;
  44. }
  45.  

Result

C++ language techstudy.org

     





Related Topics




Popular Posts