Home

A program to append two single dimensional arrays

C Programming Language 055

The following code shows how to write a program to append two single dimensional arrays.

Program

#include <stdio.h>

void main()
{
    int a[8] = {4, 3, 2}, b[5] = {7}, i, j;

    printf("Enter a elements:\n");
    for (i = 0; i <= 2; i++)
    {
        scanf("%d", &a[i]);
    }

    printf("Enter a elements in b:\n");
    for (j = 0; j <= 2; j++)
    {
        scanf("%d", &b[j]);
        a[i + j] = b[j];
    }

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

    printf("\n");
}

Result

Enter a elements:
7 6 5
Enter a elements in b:
4 3 2
a: 7 6 5 4 3 2


Last Updated on

Next Post: Rules vs Guidelines →

Comments