Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



1.write a program to merge the arrays 2.write efficient code for extracting unique elements from a ..

Answer / whyname

To merge to arrays ( Note the question has no mention of
sorting the array elements, hence the program below just
merges two arrays)

int array1[5] = {1,2,3,4,5};
int array2[7] = {6,7,8,9,10,11,12};
int i;
int merged[(sizeof(array1)+ sizeof(array2))/sizeof(int)];
memcpy( merged, array1, sizeof(array1));
memcpy( (merged+5), array2, sizeof(array2));

for(i=0;i<(sizeof(merged)/sizeof(int)); i++)
{
printf("%d\n",merged[i]);
}

Is This Answer Correct ?    20 Yes 15 No

1.write a program to merge the arrays 2.write efficient code for extracting unique elements from a ..

Answer / 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

1.write a program to merge the arrays 2.write efficient code for extracting unique elements from a ..

Answer / jaggu

#include<stdio.h>
#include<conio.h>
main()
{
int a[5]={1,2,3,4,5},b[4]={-6,-7,-8,-9},i,j=0;
for(i=5;i<=5+4-1;i++)
{

a[i]=b[j];
j++;
}
for(i=0;i<9;i++)
printf("a[%d]=%d \t",i,a[i]);

getch();
}

Is This Answer Correct ?    17 Yes 55 No

Post New Answer

More C Interview Questions

What is the mean of function?

0 Answers  


can u suggest me am in a confusion to choose whether to go to c programming or a software testing . am a graduate in B.sc(electronics).

1 Answers  


What is extern keyword in c?

0 Answers  


What is static identifier?

0 Answers   TCS,


How can I write a function that takes a format string and a variable number of arguments?

0 Answers  


difference between spiral and waterfall model

1 Answers  


what is the difference between. system call and library function?

2 Answers   CDAC, Satyam,


/*program to calculate hra,da in salary if salary less than 10000 then hra15%,da13% otherwise hra20%,da18%/*

6 Answers  


write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list

0 Answers   Persistent,


what is the difference between arrays and linked list

26 Answers   MAHINDRA, Tech Mahindra, Wipro,


what is the role you expect in software industry?

2 Answers   HCL, Wipro,


There is a mobile keypad with numbers 0-9 and alphabets on it. take input of 7 keys and then form a word from the alphabets present on those keys.

0 Answers  


Categories