Home

A program to copy single dimensional array into another

C Programming Language 054

The following code shows how to write a program to copy single dimensional array into another.

Program

#include <stdio.h>

void main()
{
    int a[5], b[5], i;

    for (i = 0; i <= 2; i++)
    {
        a[i] = i + 1;
    }

    printf("Elements of a: ");

    for (i = 0; i <= 2; i++)
    {
        printf("%d ", a[i]);
        b[i] = a[i];
    }

    printf("\nElements of b: ");

    for (i = 0; i <= 2; i++)
    {
        printf("%d ", b[i]);
    }

    printf("\n");
}

Result

Elements of a: 1 2 3 
Elements of b: 1 2 3 


Last Updated on

Next Post: Rules vs Guidelines →

Comments