
Problem :
Copy All Elements from an Array to Another Array
for loop ব্যবহার করে array traverse করা=) ব্যবহারscanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &arr1[i]);
}
for(i = 0; i < n; i++) {
arr2[i] = arr1[i];
}
printf("Elements of the copied array: ");
for(i = 0; i < n; i++) {
printf("%d ", arr2[i]);
}
#include <stdio.h>
int main() {
int n, i;
printf("Enter the number of elements: ");
scanf("%d", &n);
int arr1[n], arr2[n];
printf("Enter the elements of the first array:\n");
for(i = 0; i < n; i++) {
scanf("%d", &arr1[i]);
}
// Copy elements
for(i = 0; i < n; i++) {
arr2[i] = arr1[i];
}
printf("\nElements of the copied array: ");
for(i = 0; i < n; i++) {
printf("%d ", arr2[i]);
}
return 0;
}
Enter the number of elements: 5
Enter the elements of the first array:
10 20 30 40 50
Elements of the copied array: 10 20 30 40 50
Enter the number of elements: 3
Enter the elements of the first array:
5 -2 7
Elements of the copied array: 5 -2 7
for loop ব্যবহার করে প্রথম array-এর সব element sequentially নতুন array-তে copy করা হয়