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

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,n,b[10],m,k,temp;
clrscr();
printf("eneett the v vallrue of n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("before sorting array");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]>=a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
printf("after sorting");
for(i=0;i<n;i++)
{
printf("\n%d",a[i]);
}
for(i=0;i<n;i+=2)
{
if(a[i]!=a[i+1])
{
printf("resutl for %d,%d\n",i,a[i]);
i++;
}
}
getch();
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is return a keyword in c?

592


int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer

647


Is it possible to execute code even after the program exits the main() function?

805


why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above

605


In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.

1372






Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

2602


What is identifiers in c with examples?

672


write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1

3275


Explain how are portions of a program disabled in demo versions?

647


Which header file should you include if you are to develop a function which can accept variable number of arguments?

799


What are the types of type qualifiers in c?

642


Explain the difference between exit() and _exit() function?

630


What is wrong with this program statement?

604


What is data structure in c and its types?

587


What does 3 mean in texting?

604