write a function that accepts an array A with n elements and
array B with n-1 elements. Find the missing one in array
B,with an optimized manner?

Answer Posted / vaibhav nigam

// missing number= diff in sum of 2 arrays

int missing_number(int A[], int B[], int n)
{
int sum1=0;
for(int i=0; i<n; i++) {
sum1+=A[i];
}

int sum2=0;
for(int i=0; i<n-1; i++) {
sum2+=B[i];
}

return (sum1-sum2);
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What’s a signal? Explain what do I use signals for?

597


Differentiate between the = symbol and == symbol?

700


Write a program to compute the similarity between two strings - The program should get the two strings as input - Then it will output one single number which is the percentage of similarity between the two strings

2237


How does placing some code lines between the comment symbol help in debugging the code?

535


What are directives in c?

537






how to create duplicate link list using C???

2058


What are valid operations on pointers?

657


Is c weakly typed?

563


Why main function is special give two reasons?

935


what are the advantages of a macro over a function?

633


What is null in c?

588


Is it possible to use curly brackets ({}) to enclose single line code in c program?

780


What are the types of assignment statements?

620


What is keyword in c?

586


Can the sizeof operator be used to tell the size of an array passed to a function?

608