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
illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
How can you tell whether a program was compiled using c versus c++?
What is meant by type specifiers?
write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34
Explain what is the difference between far and near ?
What is a pointer in c plus plus?
Why void main is used in c?
Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given
What is a stream?
How do you define CONSTANT in C?
Explain what is a pragma?
How can I remove the trailing spaces from a string?
plz let me know how to become a telecom protocol tester. thank you.
Write a code to generate a series where the next element is the sum of last k terms.