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
What do header files do?
What are the two types of functions in c?
Explain how can a program be made to print the line number where an error occurs?
Is it better to use a macro or a function?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
What is the best way to store flag values in a program?
Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;
Are the variables argc and argv are local to main?
Write a program to check whether a number is prime or not using c?
Explain how can a program be made to print the name of a source file where an error occurs?
How will you declare an array of three function pointers where each function receives two ints and returns a float?
Write a program to check palindrome number in c programming?
What is the purpose of void pointer?
Why is c so important?
How to declare pointer variables?