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

#include<stdio.h>
#include<conio.h>
int main()
{
int a[15],i,j,n,temp,p,k;

printf("\nHow many elements are there in a array ");
scanf("%d",&n);
printf("\nEnter the elements ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nThe element which occur once is ");
for(i=0;i<n;i++)
{
k=2*i;
p=2*i+1;

if(a[k]!=a[p])
{
printf("%d\n",a[k]);
break;
}
}

getch();
}

Is This Answer Correct ?    0 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between ordinary variable and pointer in c.

1101


Why doesnt long int work?

980


What are the 4 types of programming language?

1049


WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.

2402


What are the usage of pointer in c?

1122


What is variable declaration and definition in c?

856


What does do in c?

991


What does sizeof return c?

1012


What is the explanation for cyclic nature of data types in c?

1140


typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

1162


Explain pointers in c programming?

1063


What is wrong with this statement? Myname = 'robin';

1264


How many levels of pointers can you have?

1135


Explain how do you list files in a directory?

1017


FILE PROGRAMMING

2179