Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 / priyanshu

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long int find(long int a[],long int n,long int f,long int l)
{
long int mid;
mid=(f+l)/2;
if(a[mid]==a[mid+1])
{
return find(a,mid,mid+1,n-1);
}
else if(a[mid]==a[mid-1])
{
return find(a,mid,0,mid-1);
}
else
return a[mid];
}

int main()
{
long int n,i;
scanf("%ld",&n);
long int a[n];
for(i=0;i<n;i++)
scanf("%ld",&a[i]);
sort(a,a+n);
printf("%ld",find(a,n,0,n-1));
return 0;
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is file a keyword in c?

887


Is there a way to jump out of a function or functions?

1028


What is the use of ?: Operator?

1080


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

1016


What is the difference between fread buffer() and fwrite buffer()?

1106


How old is c programming language?

965


Suggesting that there can be 62 seconds in a minute?

996


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

1923


the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b

2614


What is the acronym for ansi?

998


if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.

5142


What are lookup tables in c?

951


Is it fine to write void main () or main () in c?

965


Is null always defined as 0(zero)?

1042


How can you convert integers to binary or hexadecimal?

979