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
What is c method?
What are pointers really good for, anyway?
What is #include conio h?
Explain what does a function declared as pascal do differently?
What are header files in c programming?
What is default value of global variable in c?
What is the use of a conditional inclusion statement in C?
What is meant by initialization and how we initialize a variable?
Is boolean a datatype in c?
How many bytes are occupied by near, far and huge pointers (dos)?
how to introdu5ce my self in serco
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
Explain how to reverse singly link list.
What do you mean by a sequential access file?
What is the newline escape sequence?