Starting Vocational Training From 1-May-2024 Get Detail


Write a program in C to copy the elements one array into another 
array. 
Test Data : 
Input the number of elements to be stored in the array :3 
Input 3 elements in the array : 
element - 0 : 15 
element - 1 : 10 
element - 2 : 12 
Expected Output : 
The elements stored in the first array are : 
15 10 12 
The elements copied into the second array are : 
15 10 12 


#include <stdio.h> 

void main() 

   int arr1[100], arr2[100]; 
   int i, n; 

     printf(" Copy the elements one array into another array : "); 
     printf("---------------------------------------------------- "); 

     printf("Input the number of elements to be stored in the array :"); 
     scanf("%d",&n); 

     printf("Input %d elements in the array : ",n); 
     for(i=0;i<n;i++) 
      { 
              printf("element - %d : ",i); 
              scanf("%d",&arr1[i]); 
            } 
   /* Copy elements of first array into second array.*/ 
   for(i=0; i<n; i++) 
   { 
      arr2[i] = arr1[i]; 
   } 

   /* Prints the elements of first array     */ 
   printf(" The elements stored in the first array are : "); 
   for(i=0; i<n; i++) 
   { 
      printf("% 5d", arr1[i]); 

   /* Prints the elements copied into the second array. */ 
   printf(" The elements copied into the second array are : "); 
   for(i=0; i<n; i++) 
   { 
      printf("% 5d", arr2[i]); 
   } 
              printf(" ");