if array a conatins 'n' elements and array b conatins 'n-1'
elements.array b has all element which are present in array
a but one element is missing in array b. find that
element.

Answers were Sorted based on User's Feedback



if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / nikita

add the sum of elements in array a and then that of array
b.. subtract the sums of the two arrays a and b. ul get the
missing element

Is This Answer Correct ?    48 Yes 1 No

if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / sumanth

firt do sum of n elements in first array a i.e., n(n+1)/2
next the sum of n-1 elements in second array b i.e., n(n-1)/2...
from diff of these 2 sums we will get the missing element in b

Is This Answer Correct ?    30 Yes 11 No

if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / brijesh

the question says that we have to find the element which is
not there in array b but there in array a. So we can just
compare each element in a with all the elements in b and if
we don't find a match then that is the desired element.

Is This Answer Correct ?    9 Yes 3 No

if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / vadivel t

#include<stdio.h>
#include<math.h>
void main()
{
int a1[5] = {2,5,3,1,4}, a2[4] = {1,2,4,5};
int i, n = 5, sum1= 0, sum2 = 0;
for(i = 0; i <= n-1; i++)
{
sum1 = sum1 + a1[i];
if(i <= n-2)
{
sum2 = sum2 + a2[i];
}
}
printf("MISSED NO IS: %d",(sum1 - sum2));
_getch();
}

Is This Answer Correct ?    8 Yes 2 No

if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / rasika

The answers are only applicable to array of numbers.. what
if the array is of strings..?

Is This Answer Correct ?    5 Yes 1 No

if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / ajay c.

Take a temp variable of datatype of the array element.
Place a[0] in temp.

now for each element in array a compare with all elements
of array b. if any element is not found in array b, that is
the missing element.

what i guess though is that the interviewer may be trying
to look for a short-cut method to achieve the above. So, i
googled it and found a very nice answer:
http://stackoverflow.com/questions/1235033/java-comparing-
two-string-arrays-and-removing-elements-that-exist-in-both-
arrays

Is This Answer Correct ?    4 Yes 0 No

if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / furquan

@Rasika : It will work even for array of characters i.e.
string. It will calculate on the ascii value.

int main()
{
char a[] = "abcghs", b[] = "abchs";
int sum = 0,i;

int n = strlen(a);
for (i=0;i<n-1;i++){
sum += a[i] - b[i];
}
sum += a[i];

printf("%c\n",sum);
return 0;
}

Is This Answer Correct ?    3 Yes 1 No

if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / venu

use XOR association operation.
I mean: a = b^a^b = a^b^b = a;[bec a^a =0 always]

int main()
{
int a[3] = {3,4,5};
int b[4] = {7,4,5,3};
int r,i;
int n=4;

r1 = b[3];

for(i=0;i<n-1;i++)
{
r1 = r1^a[i]^b[i];
}

printf("number = %d \n",r);
}

Is This Answer Correct ?    1 Yes 0 No

if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / ajnr

if and only if it is a sorted array which consists of nos
and the elements compare have the same index no. then the
element missing in array 'b' will obviously be the 'nth'
element of array 'a'...... but this is true if the above
conditions are satisfied

Is This Answer Correct ?    1 Yes 0 No

if array a conatins 'n' elements and array b conatins 'n-1' elements.array b h..

Answer / reshma

class My
{

public static void main(String[] args) {

int a1[] = {7,6,3,1,4};
int a2[] = {4,3,7,6};

int sum1= 0;
int sum2 = 0;
for(int i=0 ;i<a1.length;i++)
{
sum1 = sum1 + a1[i];
}

for(int j=0;j<a2.length;j++)
{
sum2 = sum2 + a2[j];

}
System.out.println("MISSED NO IS: "+(sum1 - sum2));
}
}

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Interview Questions

#include<stdio.h> #include<conio.h> void main() {clrscr(); char another='y'; int num; for(;another=='y';) { printf("Enter a number"); scanf("%d",&num); printf("squre of %d is %d",num,num*num); printf("\nwant to enter another number y/n"); scanf("%c",&another); } getch(); } the above code runs only one time.on entering 'y' the screen disappeares.what can i do?

3 Answers  


What is getche() function?

0 Answers  


How do you determine whether to use a stream function or a low-level function?

0 Answers  


write a program to concatenation the string using switch case?

0 Answers  


What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?

0 Answers   Aspire, Infogain,






What is the use of bitwise operator?

0 Answers  


How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

0 Answers  


int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE) printf("1"); else printf("2"); }

2 Answers   Vector,


Describe the order of precedence with regards to operators in C.

0 Answers  


How can I find out the size of a file, prior to reading it in?

0 Answers  


‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .

0 Answers  


write a c program to find largest number in matrix(in each row,each column, diagonally, and in the whole matrix)? Its urgent.

2 Answers  


Categories