+ 1
How to copy the elements of one array into a new array.
3 Answers
+ 11
#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);
}
hope it will help đ
+ 1
Iterate over the main array and assign the values to the new array.
Loop
arr_copy[i] = arr[i];
0
Thank you âșïž