Write a C program to Copy one array into another array.

c programs

 

Write a C program to Copy one array into another array.



#include <stdio.h>

int main() {
    int n;
    printf("Enter the number of elements in the array: ");
    scanf("%d", &n);

    int sourceArray[100];
    int destinationArray[100];

    printf("Enter %d elements for the source array:\n", n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &sourceArray[i]);
    }

    // Copying elements from sourceArray to destinationArray
    for (int i = 0; i < n; i++) {
        destinationArray[i] = sourceArray[i];
    }

    printf("\nSource Array: ");
    for (int i = 0; i < n; i++) {
        printf("%d ", sourceArray[i]);
    }

    printf("\nDestination Array: ");
    for (int i = 0; i < n; i++) {
        printf("%d ", destinationArray[i]);
    }

    printf("\n");

    return 0;
}

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

You are being redirected...

10