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
What is page thrashing?
What are the functions to open and close file in c language?
Differentiate between #include<...> and #include '...'
Why & is used in c?
What is #include stdio h and #include conio h?
Can two or more operators such as and be combined in a single line of program code?
Write a program to implement queue.
Why do we use return in c?
What do you understand by friend-functions? How are they used?
Combinations of fibanocci prime series
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
What is the difference between a free-standing and a hosted environment?
What is infinite loop?
What is bash c?
how to find anagram without using string functions using only loops in c programming