Home / Programs / C Program to Copy all elements of an array into Another array
🚀 Programming Example

C Program to Copy all elements of an array into Another array

👁 2,127 Views
💻 Practical Program
📘 Step Learning
C Program to Copy all elements of an array into Another array

💻 Program Code

 /*
C Program to Copy all elements of an array into Another array
 Author: atnyla Developer
 */

  
#include <stdio.h>
 
int main() {
   int arr1[30], arr2[30], i, num;
 
   printf("\nEnter no of elements :");
   scanf("%d", &num);
 
   //Accepting values into Array
   printf("\nEnter the values :");
   for (i = 0; i < num; i++) {
      scanf("%d", &arr1[i]);
   }
 
   /* Copying data from array 'a' to array 'b */
   for (i = 0; i < num; i++) {
      arr2[i] = arr1[i];
   }
 
   //Printing of all elements of array
   printf("The copied array is :");
   for (i = 0; i < num; i++)
      printf("\narr2[%d] = %d", i, arr2[i]);
 
   return (0);
}
                        

🖥 Program Output


Enter no of elements :5

Enter the values :1
2
3
4
5
The copied array is :
arr2[0] = 1
arr2[1] = 2
arr2[2] = 3
arr2[3] = 4
arr2[4] = 5 
                            

📘 Explanation

C Program to Copy all elements of an array into Another array
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.