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
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
What is the Purpose of 'extern' keyword in a function declaration?
write a program to copy the string using switch case?
what are # pragma staments?
A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
Describe the difference between = and == symbols in c programming?
If you know then define #pragma?
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
What are identifiers c?
Give the rules for variable declaration?
What is pointer in c?
What is the difference between NULL and NUL?
What are multidimensional arrays?
What is getch?