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 union and structure in c?
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
Which is better malloc or calloc?
Why is event driven programming or procedural programming, better within specific scenario?
Why does everyone say not to use gets?
What are compound statements?
Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?
hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel
What is the advantage of an array over individual variables?
How pointer is different from array?
What should malloc() do? Return a null pointer or a pointer to 0 bytes?
What is array in C
difference between native and cross compilers
What is a lookup table in c?
How do you determine whether to use a stream function or a low-level function?