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:
No comments:
Post a Comment