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...

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 are control structures? What are the different types?

1141


What is the difference between char array and char pointer?

1115


What is strcmp in c?

1209


The difference between printf and fprintf is ?

1337


What are the 5 types of inheritance in c ++?

1071


Do string constants represent numerical values?

1445


Where are the auto variables stored?

1203


How many keywords (reserve words) are in c?

1184


What do you mean by dynamic memory allocation in c?

1148


Why is c so popular?

1203


Should I learn data structures in c or python?

1067


What is meant by realloc()?

1200


How to write a code for reverse of string without using string functions?

2197


cavium networks written test pattern ..

4138


What is c basic?

1219