This c program will copy all the elements from an array to Another array with the help of for loop. Copy the below program and execute it with help of the c compiler.
We assume you have basic knowledge of c programming language, Array in c programming, For loop in c.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<stdio.h> int main() { int arr1[30], arr2[30], i, num; printf("\nEnter the number of array elements:"); scanf("%d", &num); printf("\nEnter the array elements:"); for (i = 0; i < num; i++) { scanf("%d", &arr1[i]); } /* now copying array1 to array2 */ 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); } |
Enter the number of array elements:5
Enter the array elements:30
60
80
70
60
The copied array is:
arr2[0] = 30
arr2[1] = 60
arr2[2] = 80
arr2[3] = 70
arr2[4] = 60
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: array in c, array in c language, c program examples, c program examples with output, c programs, c programs with solutions, list of important c programs, what is array in c