You have an array of n integers, randomly ordered with value 1
to n-1.The array is such that there is only one and one value
occurred twice. How will you find this number?
Answer Posted / balaji ganesh
#include<stdio.h>
void main()
{
int a[100],n,i,j;
clrscr();
scanf("%d",&n,printf("enter size of array:"));
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]==a[j])
{
printf("second occurence value: %d",a[i]);
break;
}
getch();
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What are local static variables?
Explain logical errors? Compare with syntax errors.
What is the correct code to have following output in c using nested for loop?
I heard that you have to include stdio.h before calling printf. Why?
What are the string functions? List some string functions available in c.
Can one function call another?
What is a wrapper function in c?
What is difference between main and void main?
In a header file whether functions are declared or defined?
When should a type cast not be used?
Is it acceptable to declare/define a variable in a c header?
Is null equal to 0 in sql?
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
What is the meaning of && in c?
When is a void pointer used?