Given an array of numbers, except for one number all the
others occur twice. Give an algorithm to find that number
which occurs only once in the array.
Answer Posted / guest
int arr[n]; //n' numbers
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
{ if ( (a[i]==a[j])&&i!=j ) break; //ITS NOT THE NUM
if ( (a[i]!=a[j])&&j==n-1) return i; //IT IS!!
return -1; //IF THERE IS NO SUCH NUMBER...
| Is This Answer Correct ? | 3 Yes | 7 No |
Post New Answer View All Answers
Explain how can I pad a string to a known length?
Explain what is the benefit of using enum to declare a constant?
How do you determine a file’s attributes?
What is a header file?
What is the use of function in c?
What is meant by inheritance?
Differentiate between a for loop and a while loop? What are it uses?
What is a void * in c?
How does normalization of huge pointer works?
Describe newline escape sequence with a sample program?
What does 4d mean in c?
what are enumerations in C
Explain what are bus errors, memory faults, and core dumps?
What is the purpose of the preprocessor directive error?
What are actual arguments?