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

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

1 Answers  


write a c program to Reverse a given string using string function and also without string function

1 Answers  


To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

0 Answers  


Write a program using one dimensional array to assign values and then display it on the screen. Use the formula a[i]=i*10 to assign value to an element.

1 Answers   Samar State University,


main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b)); } a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above

4 Answers   Corporate Society, HCL,






int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().

2 Answers  


main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024

2 Answers   HCL,


main() { int i, n; char *x = “girl”; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) { printf(“%s\n”,x); x++; } }

2 Answers  


4. Main() { Int i=3,j=2,c=0,m; m=i&&j||c&I; printf(“%d%d%d%d”,I,j,c,m); }

2 Answers   Broadridge,


find A^B using Recursive function

2 Answers  


Write a program to receive an integer and find its octal equivalent?

7 Answers  


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

0 Answers   TCS,


Categories