Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

Advertisements


website counter



C program-Program of merging two sorted arrays into a third sorted array


Posted Date: 10 Jun 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: Girish Patil       Member Level: Diamond
Rating:     Points: 2



/* Program of merging two sorted arrays into a third sorted array*/
#include

main()
{
int arr1[20],arr2[20],arr3[40];
int i,j,k;
int max1,max2;

printf("Enter the number of elements in list1 : ");
scanf("%d",&max1);
printf("Take the elements in sorted order :\n");
for(i=0;i {
printf("Enter element %d : ",i+1);
scanf("%d",&arr1[i]);
}
printf("Enter the number of elements in list2 : ");
scanf("%d",&max2);
printf("Take the elements in sorted order :\n");
for(i=0;i {
printf("Enter element %d : ",i+1);
scanf("%d",&arr2[i]);
}
/* Merging */
i=0; /*Index for first array*/
j=0; /*Index for second array*/
k=0; /*Index for merged array*/

while( (i < max1) && (j < max2) )
{
if( arr1[i] < arr2[j] )
arr3[k++]=arr1[i++];
else
arr3[k++]=arr2[j++];
}/*End of while*/
/*Put remaining elements of arr1 into arr3*/
while( i < max1 )
arr3[k++]=arr1[i++];
/*Put remaining elements of arr2 into arr3*/
while( j < max2 )
arr3[k++]=arr2[j++];

/*Merging completed*/
printf("List 1 : ");
for(i=0;i printf("%d ",arr1[i]);
printf("\nList 2 : ");
for(i=0;i printf("%d ",arr2[i]);
printf("\nMerged list : ");
for(i=0;i printf("%d ",arr3[i]);
printf("\n");
}/*End of main()*/




Responses

Author: Lenin    10 Jun 2008Member Level: Diamond   Points : 2
hi giri are you a computer student , i know only small programs in C.But i know C is a SEA.Am i right ? I remember the days when i used to mugup the codings for Lab exams.still c fear is there.
Also still C is in flying colours


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: C program-Program for binary search
Previous Resource: All about World Wide Web
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources


Contact Us    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.