Anasayfa
/
Teknoloji
/
Write a Program in C to Copy the Elements of One Array into Another Array. Read the Input and Store It in the First Array . Copy Each

Soru

Write a program in C to copy the elements of one array into another array. Read the input and store it in the first array . Copy each element from the first array to the second array. Then print each element in the second array. Write the program in word or in code editor and upload it here.

Çözüm

4.4 (216 Oylar)
Sait
Uzman doğrulaması
Profesyonel · 6 yıl öğretmeni

Cevap

Here is a sample program in C that copies the elements of one array into another array:```c#include int main() { int arr1[] = {1, 2, 3, 4, 5}; int arr2[5]; // Copy elements from arr1 to arr2 for (int i = 0; i < 5; i++) { arr2[i] = arr1[i]; } // Print elements in arr2 for (int i = 0; i < 5; i++) { printf("%d ", arr2[i]); } return 0;}```In this program, we first define two arrays `arr1` and `arr2`. We then use a `for` loop to copy each element from `arr1` to `arr2`. Finally, we print each element in `arr2` using another `for` loop.