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
What are loops in c?
Can static variables be declared in a header file?
Explain the difference between null pointer and void pointer.
How do you define a function?
Is boolean a datatype in c?
Explain what are bus errors, memory faults, and core dumps?
explain how do you use macro?
What is the difference between far and near in c?
using only #include
Write a program to check palindrome number in c programming?
how to write optimum code to divide a 50 digit number with a 25 digit number??
How do you determine the length of a string value that was stored in a variable?
Why isnt there a numbered, multi-level break statement to break out
Implement bit Array in C.
What is meant by type specifiers?