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
Why c language is called c?
How can I find out how much free space is available on disk?
What is selection sort in c?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
Tell me what is the purpose of 'register' keyword in c language?
Disadvantages of C language.
How can I open a file so that other programs can update it at the same time?
State the difference between x3 and x[3].
What is the use of putchar function?
What does return 1 means in c?
Explain what are reserved words?
What is hashing in c language?
code for find determinent of amatrix
What is a pointer variable in c language?
How can I write a function that takes a format string and a variable number of arguments?