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

main() { int y; scanf("%d",&y); // input given is 2000 if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year"); else printf("%d is not a leap year"); }

1 Answers  


How we will connect multiple client ? (without using fork,thread)

3 Answers   TelDNA,


main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }

1 Answers  


main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }

1 Answers  


plz send me all data structure related programs

2 Answers  






write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details

2 Answers   TCS,


Display the time of the system and display the right time of the other country

1 Answers  


why nlogn is the lower limit of any sort algorithm?

0 Answers  


union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0

1 Answers   HCL,


#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }

2 Answers  


How can i find first 5 natural Numbers without using any loop in c language????????

2 Answers   Microsoft,


PROG. TO PRODUCE 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

1 Answers  


Categories