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() { printf("%x",-1<<4); }

3 Answers   HCL, Sokrati, Zoho,


union u { union u { int i; int j; }a[10]; int b[10]; }u; main() { printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a)); // printf("%d", sizeof(u.a[4].i)); } a. 4, 4, 4 b. 40, 4, 4 c. 1, 100, 1 d. 40 400 4

3 Answers   HCL,


int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }

3 Answers   Cisco, HCL,


main() { char *p = “ayqm”; printf(“%c”,++*(p++)); }

29 Answers   IBM, TCS, UGC NET, Wipro,


What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;

1 Answers  


main() { printf("\nab"); printf("\bsi"); printf("\rha"); }

3 Answers  


What are segment and offset addresses?

2 Answers   Infosys,


How to access command-line arguments?

4 Answers  


I need your help, i need a Turbo C code for this problem.. hope u'll help me guys.? Your program will have a 3x3 array. The user will input the sum of each row and each column. Then the user will input 3 values and store them anywhere, or any location or index, temporarily in the array. Your program will supply the remaining six (6) values and determine the exact location of each value in the array. Example: Input: Sum of row 1: 6 Sum of row 2: 15 Sum of row 3: 24 Sum of column 1: 12 Sum of column 2: 15 Sum of column 3: 18 Value 1: 3 Value 2: 5 Value 3: 6 Output: Sum of Row 1 2 3 6 4 5 6 15 7 8 9 24 Sum of Column 12 15 18 Note: Your program will not necessary sort the walues in the array Thanks..

0 Answers  


main() { int c = 5; printf("%d", main||c); } a. 1 b. 5 c. 0 d. none of the above

2 Answers   HCL,


/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }

4 Answers  


void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }

3 Answers  


Categories