You are here:

C/Merging Array !

Advertisement


Question
how can i merge the two sorted arrays into a single array? i need to know the codes

Answer
Hai Dear bhadz !
 
We can append the contents of the one array with another array ( merging ) but its not possible to fuse two array's into a single array !

Presenting you a simple code that will merge the contents of the arr2 with arr1

#include<stdio.h>

void main()
{
  int arr1[20] = { 10  , 20  , 30 , 40 , 50};
  int arr2[] = { 60 , 70 , 80 , 90 , 100};
  int i;
  
  /* Given arr1 and arr2 are the two sorted arrays of length 5 , 5 respectivly
   Following code will merg the contents of arr2 with the contents of arr1 */

  for( i = 0 ; i < 5 ; i++)
     arr1[i+5] = arr2[i];
  /* Print the contents of the arr1 */

  printf("Contents of the arr1 after merging :");

  for( i = 0 ; i < 10 ;i++)
     printf("%d " , arr1[i]);
}

Note : If you are looking for a different answer , please specify your question clearly , your question will be answered in short !

Thanks and Regards !
Prince M. Premnath

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.