write a program in c to merge two array

Answers were Sorted based on User's Feedback



write a program in c to merge two array..

Answer / priti rachana

#include<stdio.h>
#include<conio.h>
void main()
{
int p,q,m,n,c;
int a1[100],a2[100],a3[100];
puts("enter the number of elements of the 1st sorted array");
scanf("%d",&p);
puts("enter number ofthe 1st sorted array");
for(m=0;<=p-1;m++)
scanf("%d",&a1[m]);
puts("enter number of element of the 2nd sorted array");
scanf("%d",&q);
puts(enter element of the 2nd sorted array");
for(n=0;n<=q-1;n++)
scanf("%d",&a2[n]);
c=0;
m=0;
n=0;
while((m<p)&&(n<q))
{
if(a1[m]<=a2[n])
a3[c]=a1[m++];
else
a3[c]=a2[n++];
c++;
}
while(m<p)
{
a3[c]=a2[n];
c++;
n++;
}
puts("merged array in asending order");
for(m=0;m<=c-1;m++)
printf("%d\n",a3[m]);
}

puts("enter the number of elements in the 2nd sorted arra array");
scanf("%d",&q);

Is This Answer Correct ?    10 Yes 4 No

write a program in c to merge two array..

Answer / ashok kannan

#include<stdio.h>
void main()
{
int a[]={1,1,2,3,4,5},b[]={2,3,4,5,6};
int i,j;
for(i=0;a[i]!='\0';i++);

for(j=0;b[j]!='\0';j++)
{
a[i]=b[j];
i++;
}

for(i=0;a[i]!='\0';i++)
printf("%d",a[i]);

}

Is This Answer Correct ?    14 Yes 29 No

Post New Answer

More C Code Interview Questions

3) Int Matrix of certain size was given, We had few valu= es in it like this. =97=97=97=97=97=97=97=97=97=97=97 1 = | 4 | | 5 | &= nbsp; | 45 =97=97=97=97=97=97=97=97=97=97=97 &n= bsp; | 3 | 3 | 5 | = | 4 =97=97=97=97=97=97=97=97=97=97=97 34 |&nbs= p; 3 | 3 | | 12 | &= nbsp; =97=97=97=97=97=97=97=97=97=97=97 3 | &nbs= p; | 3 | 4 | = | 3 =97=97=97=97=97=97=97=97=97=97=97 3 | = ; | | | = ; 3 | =97=97=97=97=97=97=97=97=97=97=97 &= nbsp; | | 4 | = ; | 4 | 3 We w= ere supposed to move back all the spaces in it at the end. Note: = If implemented this prog using recursion, would get higher preference.

0 Answers   RoboSoft,


Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.

9 Answers   Microsoft,


How we print the table of 3 using for loop in c programing?

7 Answers  


How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?

0 Answers  


#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above

3 Answers   HCL,






programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h

1 Answers  


#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }

1 Answers  


main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }

1 Answers   Zoho,


Write a routine that prints out a 2-D array in spiral order

3 Answers   Microsoft,


int a = 10 + 10 .... ,... A = A * A What would be the value of A? The answer is 120!! Could anyone explain this to me.

2 Answers   Bosch, eInfochips, HCL, IHCL,


program to find magic aquare using array

4 Answers   HCL,


Write, efficient code for extracting unique elements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).

13 Answers   Intel, Microsoft, TCS,


Categories