Write a program to copy the elements of one array into another array

Write a program to copy the elements of one array into another array

  1. #include <stdio.h>

  2. void main()
  3. {
  4.     int arr1[100];
  5.     int arr2[100];
  6.     int i, n;
  7.     printf("Input the number of elements to be stored in the array : ");
  8.     scanf("%d", &n);

  9.     printf("Enter %d elements in the array :\n", n);
  10.     for(i=0; i<n; i++) {
  11.         printf("Element - %d : ", i);
  12.         scanf("%d", &arr1[i]);
  13.     }
  14.         
  15.     //Copy elements of first array into second array 
  16.     for(i=0; i<n; i++) {
  17.         arr2[i] = arr1[i];
  18.     }

  19.     printf("The elements copied from first array into second array : ");
  20.     for(i=0; i<n; i++) {
  21.         printf("%5d", arr2[i]);
  22.     }
  23. }

একটি মন্তব্য পোস্ট করুন