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
Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result
What math functions are available for integers? For floating point?
Explain threaded binary trees?
What is a lvalue
Does c have class?
Explain what is the difference between #include and #include 'file' ?
while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above
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.
Explain what are the standard predefined macros?
Write a program to know whether the input number is an armstrong number.
What is the meaning of c in c language?
Explain function?
while initialization of array why we use a[][2] why not a[2][]...?
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
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?