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


Please Help Members By Posting Answers For Below Questions

What are loops in c?

545


Can static variables be declared in a header file?

612


Explain the difference between null pointer and void pointer.

663


How do you define a function?

579


Is boolean a datatype in c?

540






Explain what are bus errors, memory faults, and core dumps?

785


explain how do you use macro?

665


What is the difference between far and near in c?

599


using only #include and #include Write a program in C that will read an input from the user and print it back to the user if it is a palindrome. The string ends when it encounters a whitespace. The input string is at most 30 characters. Assume the string has no spaces and distinguish between and lowercase. So madam is a palindrome, but MadAm is not a palindrome. Use scanf and %s to read the string. Sample Test: Enter a string: madam madam is a palindrome. Enter a string: 09023 09023 is not a palindrome.

1306


Write a program to check palindrome number in c programming?

596


how to write optimum code to divide a 50 digit number with a 25 digit number??

2747


How do you determine the length of a string value that was stored in a variable?

647


Why isnt there a numbered, multi-level break statement to break out

583


Implement bit Array in C.

672


What is meant by type specifiers?

657