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

What is c method?

531


What are pointers really good for, anyway?

610


What is #include conio h?

587


Explain what does a function declared as pascal do differently?

634


What are header files in c programming?

651






What is default value of global variable in c?

558


What is the use of a conditional inclusion statement in C?

594


What is meant by initialization and how we initialize a variable?

581


Is boolean a datatype in c?

540


How many bytes are occupied by near, far and huge pointers (dos)?

664


how to introdu5ce my self in serco

1521


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

2020


Explain how to reverse singly link list.

603


What do you mean by a sequential access file?

621


What is the newline escape sequence?

580