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
What is the importance of c in your views?
What is function pointer c?
Why pointers are used?
What are header files? What are their uses?
What is structure in c definition?
What are the advantages of using linked list for tree construction?
Can you write the algorithm for Queue?
Explain modulus operator.
Explain what are its uses in c programming?
4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.
What is I ++ in c programming?
What is 02d in c?
What is memory leak in c?
Explain the Difference between the New and Malloc keyword.
Write a program to implement queue.