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 a loop?
Do you know the difference between exit() and _exit() function in c?
How do you determine the length of a string value that was stored in a variable?
what are bit fields in c?
List the difference between a "copy constructor" and a "assignment operator"?
Why isnt there a numbered, multi-level break statement to break out
What is a global variable in c?
Is it possible to use curly brackets ({}) to enclose single line code in c program?
What are the types of data structures in c?
Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?
What is restrict keyword in c?
Write a program to check palindrome number in c programming?
Explain a pre-processor and its advantages.
Explain what is the concatenation operator?
Where are local variables stored in c?