1.find the second maximum in an array?
2.how do you create hash table in c?
3.what is hash collision

Answers were Sorted based on User's Feedback



1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collisi..

Answer / sachin

1.#include<stdio.h>
int main()
{
int a[10]={222,111,4,5,6,8,1,77,0,4};
int i=0,max=0,sec_max=0;

for(i=0;i<10;i++)
{
if(a[i]>max)
{
sec_max=max;
max=a[i];
}
else if(a[i]>sec_max)
{
sec_max=a[i];
}


}

printf("Max= %d Second Max=%d",max,sec_max);

}

Is This Answer Correct ?    23 Yes 2 No

1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collisi..

Answer / steven le

1. Selection sort with second pass
2. Basically we create a two dimension array (key, value)
and then we define a hash function to determine position of
elements when we insert/delete.
3. When two elements insert to the same spot in a hash
table, we have a hash collision. H(x1) = H(x2) = y

Is This Answer Correct ?    5 Yes 2 No

1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collisi..

Answer / abdur rab

#include <stdio.h>

int main ( int argc, char* argv[] )
{

int* array_int, nTotalCount = 10, sbig, big, i;
printf ( "\n/********************** Second Biggest
Number ********************/" );
array_int = ( int* ) malloc ( nTotalCount * sizeof
( int ) );

for ( i = 0; i < nTotalCount; i++ )
array_int [i] = rand() % 100;

printf( "\nThe Numbers in given order" );
for ( i = 0; i < nTotalCount; i++ )
printf ( "\t%d", array_int [i] );

for ( i = 0; i < nTotalCount; i++ )
{
switch ( i )
{
case 0:
sbig = big = array_int [i];
break;
default:
if ( big < array_int [i] ) {
sbig = big;
big = array_int [i];
} else {
if ( sbig <
array_int [i] ) sbig = array_int [i] ;
}
break;
}
}
printf ( "\n sbig :%d big :%d", sbig, big );

free ( array_int );
}


For hashtable please refer the following link
http://www.geocities.com/abdur_rab7/Open_Hash/openhash.html

Is This Answer Correct ?    3 Yes 2 No

1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collisi..

Answer / dishant srivastava

void max_two(unsigned char A[], unsigned char Size,
unsigned char *first, unsigned char *second)
{
unsigned char i;
*first = A[0];

for(i = 1; i < Size; i++)
{
if(*first <= A[i])
{
*second = *first;
*first = A[i];
}
}
}

Is This Answer Correct ?    1 Yes 0 No

1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collisi..

Answer / shanthi

#include<stdio.h>

int main()
{
int array[5]={2,3,4,6,5};
int max=a[0];
int sec=a[1];
for(i=0;i<5;i++)
{
if(a[i]>max)
max=a[i];
}

for(i=0;i<5;i++)
{
if((a[i]>sec )&&(a[i]<max))
{
sec=a[i];
}
}
printf("%d %d",max,sec);
}

Is This Answer Correct ?    1 Yes 0 No

1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collisi..

Answer / rao

#include<stdio.h>

int main()
{
int arr[] = {2,3,20,7,8,1};
int max, sec;
int i;
max=0;
sec=0;
for ( i=0; i< 6; i++)
{
if(arr[i] > max)
max = arr[i];
}

for ( i=0; i< 6; i++)
{
if ( (arr[i] > sec) && (arr[i] < max))
sec = arr[i];
}
printf(" max=%d\n sec=%d\n", max, sec);
}

Is This Answer Correct ?    2 Yes 2 No

1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collisi..

Answer / shanthi

2.

hash table is a table with one row with 10 columns say.
now to create hash table

struct phonerec
{
char name;
int phoneno;
};

struct node
{
struct phonerec r;
struct node *pnext;
};

struct node *hash[10];

int hashfun(int phoneno)
{
return phone%10;

}

int add(struct phonerec *pr);
{
struct node *pn;
pn = malloc(sizeof(*pn));
pn->r=*pr;
int hix=hashfun(pr->phoneno);
pn->pnext=hasharray[hix];
hasharray[hix]=pn;
return SUCCESS;
}

Is This Answer Correct ?    0 Yes 0 No

1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collisi..

Answer / jaypal rajput

//find second maximum number in given array.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5];
int max=0,secmax=0,i;
cout<<"Enter element";
for(i=0;i<=4;i++)
{
cin>>a[i];
}
for(i=0;i<=4;i++)
{
if(a[i]>max)
{
secmax=max;
max=a[i];
}
if(a[i]>secmax&&a[i]<max)
{
secmax=a[i];
}
}
cout<<"The max element is="<<max;
cout<<"the sec max is="<<secmax;
getch();
}

Is This Answer Correct ?    0 Yes 1 No

1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collisi..

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
void soft(int *,int *);
void main()
{
int a[30],n;
printf("enter the number of elements going to enter :");
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",a[i]);
soft(a);
printf("the second maximum in the given array is :");
getch();
}
void soft(int *a,int *n);
{
int temp;
for(int i=0;i<(*n);i++)
{
for(j=0;j<(*n);j++)
{
if(a[j+1]<a[j])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
printf("%d",a[n-1]);
}

sorry i dont know the concept of hash table!!!!!!!!!!!!!!!

Is This Answer Correct ?    1 Yes 18 No

Post New Answer

More C Interview Questions

void main() { int a=1; printf("%d %d %d",a,++a,a++); } the output is supposed to be 1 2 2....but it is 3 3 1 this is due to calling conventions of C. if anyone can explain me how it happens?

7 Answers  


Do you know null pointer?

0 Answers  


what does ‘segmentation violation’ mean?

1 Answers  


#include<stdio.h> void main() { int a,b,c; a=b=c=1; c=++a || ++b && ++c; printf("%d\t%d\t%d",a,b,c); }

3 Answers  


How do you determine whether to use a stream function or a low-level function?

0 Answers  






what is the most appropriate way to write a multi-statement macro?

1 Answers  


how to swap 2 numbers within a single statement?

4 Answers  


What is Conio.h ?

2 Answers   TCS,


What is variable and explain rules to declare variable in c?

0 Answers  


15.what is the disadvantage of using macros? 16.what is the self-referential structure? 17.can a union be self-referenced? 18.What is a pointer? 19.What is the Lvalue and Rvalue? 20.what is the difference between these initializations? 21.Char a[]=”string”; 22.Char *p=”literal”; 23.Does *p++ increment p, or what it points to?

2 Answers   CTS,


Simplify the program segment if X = B then C &#8592; true else C &#8592; false

0 Answers  


How to write in a function declaration and in function call in which the function has 'n' number of varible or arguments?

2 Answers  


Categories