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
Differentiate between ordinary variable and pointer in c.
Why doesnt long int work?
What are the 4 types of programming language?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What are the usage of pointer in c?
What is variable declaration and definition in c?
What does do in c?
What does sizeof return c?
What is the explanation for cyclic nature of data types in c?
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
Explain pointers in c programming?
What is wrong with this statement? Myname = 'robin';
How many levels of pointers can you have?
Explain how do you list files in a directory?
FILE PROGRAMMING