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 / pushpa

int num[3];
int i,j,p=0,count_1=0,count=0,n;

n= 3;
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}


for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(num[i] == num[j])
count_1=0;
else
count++;
}
if(count == n-1)
{
printf("The number which occurs once is %d\n",num[i]);
}
count = 0;

}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result

1467


What math functions are available for integers? For floating point?

616


Explain threaded binary trees?

670


What is a lvalue

655


Does c have class?

608






Explain what is the difference between #include and #include 'file' ?

579


while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above

732


Write the program with at least two functions to solve the following problem. The members of the board of a small university are considering voting for a pay increase for their 10 faculty members. They are considering a pay increase of 8%. Write a program that will prompt for and accept the current salary for each of the faculty members, then calculate and display their individual pay increases. At the end of the program, print the total faculty payroll before and after the pay increase, and the total pay increase involved.

2644


Explain what are the standard predefined macros?

647


Write a program to know whether the input number is an armstrong number.

663


What is the meaning of c in c language?

592


Explain function?

659


while initialization of array why we use a[][2] why not a[2][]...?

1861


what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above

667


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

562