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
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
What is the difference between arrays and pointers?
What is the size of array float a(10)?
How do I send escape sequences to control a terminal or other device?
Write a client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer
write a program to display the numbers in the following format 4 4 3 3 3 3 2 2 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 4
if the address of a[1,1] and a[2,1] are 1000 and 1010 respectively and each occupies 2 bytes then the array has been stored in what order?
4 Answers Amazon, Apple, Bata, Google, NASA,
What is function prototype?
what is computer engg
write a program to check whether a given integer is a strong number or not? [Hint: 145=1!+4!+5! =1+24+120 =145]
Write a c program to sort six numbers and find the largest one by using the ladder of if-else? plz do help me
#include<stdio.h> main() { char *p1; char *p2; p1=(char *) malloc(25); p2=(char *) malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf("%s",p1); } Tell me the output?
Write a program to print ASCII code for a given digit.