1.write a program to merge the arrays
2.write efficient code for extracting unique elements from a
sorted list of array?

Answer Posted / nishant chauhan

//#include<stdio.h>
#include<conio.h>
#include<iostream>
using namespace std;

int merge(int A[],int B[],int C[],int m,int n)
{
int i=0, j=0, k=0,len=0;
while (i < m && j < n)
{
if (A[i] <B[j])
{
C[k] = A[i];
i++;
len++;
}
else if(A[i] >B[j])
{
C[k] = B[j];
j++;
len++;
}
else
{
C[k]=A[i];
i++;j++;
len++;
}
k++;
}

if (i < m)
{
for (int p = i; p < m; p++)
{
C[k] = A[p];
k++;len++;
}

}
else
{
for (int p = j; p < n; p++)
{
C[k] = B[p];
k++; len++;
}
}
return len;
}

main ()
{
int a[20],b[20],c[30],m,n;
cout<<"enter the length of first array: ";
cin>>m;
cout<<"enter the array: ";
for(int i=0;i<m;i++)
cin>>a[i];
cout<<"enter the length of second array: ";
cin>>n;
cout<<"enter the array: ";
for(int j=0;j<n;j++)
cin>>b[j];
int length=merge(a,b,c,m,n);
cout<<"resulting merging array is: ";
for(int k=0;k<length;k++)
cout<<c[k]<<" ";
getch();
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is wrong in this statement? scanf(“%d”,whatnumber);

948


What is the importance of c in your views?

785


How do c compilers work?

777


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

846


The statement, int(*x[]) () what does in indicate?

867






Why should I prototype a function?

812


what do you mean by enumeration constant?

764


write a program to print largest number of each row of a 2D array

2074


how to capitalise first letter of each word in a given string?

1646


can anyone please tell about the nested interrupts?

1848


why we wont use '&' sing in aceesing the string using scanf

2045


When should a type cast not be used?

806


write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a

1637


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

2064


What are the types of variables in c?

745