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.4216 Voting
Sait
Profesyonel · 6 yıl öğretmeniUzman doğrulaması
Cevap
Here is a sample program in C that copies the elements of one array into another array:<br />```c<br />#include <stdio.h><br /><br />int main() {<br /> int arr1[] = {1, 2, 3, 4, 5};<br /> int arr2[5];<br /><br /> // Copy elements from arr1 to arr2<br /> for (int i = 0; i < 5; i++) {<br /> arr2[i] = arr1[i];<br /> }<br /><br /> // Print elements in arr2<br /> for (int i = 0; i < 5; i++) {<br /> printf("%d ", arr2[i]);<br /> }<br /><br /> return 0;<br />}<br />```<br />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.
Derecelendirmek için tıklayın: