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
How do you define a function?
What Is The Difference Between Null And Void Pointer?
What is a pointer and how it is initialized?
Can a variable be both const and volatile?
Why is c still so popular?
What is the difference between test design and test case design?
Why double pointer is used in c?
Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.
which is conditional construct a) if statement b) switch statement c) while/for d) goto
In C programming, how do you insert quote characters (‘ and “) into the output screen?
What are the disadvantages of c language?
What is an arrays?
What is the symbol indicated the c-preprocessor?
Explain how can a program be made to print the line number where an error occurs?
Why C language is a procedural language?