C program to merge two arrays into single array
Simple C program to merge two arrays into a single array
Code:
#include<stdio.h>#include<conio.h>
int main(){
int a[50],b[50],c[100],i,j=0,n,m;
clrscr();
printf("Enter the length of first array: ");
scanf("%d",&n);
printf("Enter the length of second array: ");
scanf("%d",&m);
printf("Enter the element of FIRST array: ");
for (i=0;i<n;i++){
scanf("%d",&a[i]);}
printf("Enter the element of second array: ");
for(i=0;i<m;i++){
scanf("%d",&b[i]);}
for (i=0;i<(n+m);i++){
if(i>n-1){
c[i]=b[j];
j++;
}
else{
c[i]=a[i];
}
}
Printf(“The final Array: ”);
for (i=0;i<(m+n);i++){
printf("\n%d",c[i]);
}
getch();
}
Comments
Post a Comment