20_10

Write a C program to merge two one dimensional array elements in one dimensional third array.

Source code:

 //Merge two one dimensional array elements in one dimensional third array

#include <stdio.h>

int main()

{

    int arr1[5];

    int arr2[5];

    int arr3[10];

int i=0,j=0;

 /*Read array elements*/

  printf("For 1st array:-\n");

    for (i=0; i<5; i++)

    {

    printf("Enter the value for %d: ",i);

        scanf("%d",&arr1[i]);

    }

    printf("For 2nd array:-\n");

    for (i=0; i<5; i++)

    {

    printf("Enter the value for %d: ",i);

        scanf("%d",&arr2[i]);

}

for(i=0;i<5;i++)

{

  arr3[i]=arr1[i];

}

for(j=5,i=0;j<10,i<5;j++,i++)

{

  arr3[j]=arr2[i];

}

for (i=0; i < 10; i++)

{

    printf ("%d\n",arr3[i]);

}

return (0);

}

Output:

Merge two one dimensional array elements in one dimensional third array


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...