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?

Answers were Sorted based on User's Feedback



write a function that accepts an array A with n elements and array B with n-1 elements. Find the mi..

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

write a function that accepts an array A with n elements and array B with n-1 elements. Find the mi..

Answer / aravind

#include<stdio.h>
int missing_item(int,int);
int main()
{
int a[10];
int b[9];
printf("enter size of array");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the elemets of array a ");
scanf("%d",&a);
}

for(i=0;i<n-1;i++)
{
printf("enter b elements");
scanf("%d",&b);
missing_item(int c,int d)
{
int item;
for(i=0;i<n;i++)
{
if(c[i]==d[i])
break;
else
{
item=c[i];
printf("the missing item is=%d",c[i]);
}

}

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Interview Questions

Write code for initializing one dimentional and two dimentional array in a C Program?

5 Answers   Deshaw, Edutech, GMD,


Which is the memory area not included in C program? give the reason

0 Answers   IBM, TCS,


What is static memory allocation? Explain

0 Answers  


Is there a way to compare two structure variables?

0 Answers  


Suppose I want to write a function that takes a generic pointer as an argument and I want to simulate passing it by reference. Can I give the formal parameter type void **, and do something like this? void f(void **); double *dp; f((void **)&dp);

1 Answers  


Why functions are used in c?

0 Answers  


how to make program without <> in library.

1 Answers   ADITI,


What is the output for the program given below typedef enum grade{GOOD,BAD,WORST,}BAD; main() { BAD g1; g1=1; printf("%d",g1); }

4 Answers   ADITI,


What is const and volatile in c?

0 Answers  


what is the difference between declaration and definition of a variable or function ?

3 Answers  


Can a program have multiple main() functions?

1 Answers  


What will be the output of following program #include main() { int x,y = 10; x = y * NULL; printf("%d",x); }

1 Answers  


Categories