+ 1

How to copy the elements of one array into a new array.

5th Feb 2022, 3:25 PM
Varshini M
Varshini M - avatar
3 Respuestas
+ 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 🙂
6th Feb 2022, 12:59 AM
Vaibhav
Vaibhav - avatar
+ 1
Iterate over the main array and assign the values to the new array. Loop arr_copy[i] = arr[i];
5th Feb 2022, 7:01 PM
Kashyap Kumar
Kashyap Kumar - avatar
0
Thank you ☺️
10th Feb 2022, 2:44 PM
Varshini M
Varshini M - avatar