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
What are control structures? What are the different types?
What is the difference between char array and char pointer?
What is strcmp in c?
The difference between printf and fprintf is ?
What are the 5 types of inheritance in c ++?
Do string constants represent numerical values?
Where are the auto variables stored?
How many keywords (reserve words) are in c?
What do you mean by dynamic memory allocation in c?
Why is c so popular?
Should I learn data structures in c or python?
What is meant by realloc()?
How to write a code for reverse of string without using string functions?
cavium networks written test pattern ..
What is c basic?