# include <iostream.h>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
# include <math.h>
int main( )
{
clrscr( );
cout << endl << "Mid-Square Hashing Method" << endl;
cout << "*************************" << endl << endl;
unsigned int iNumber = 0;
unsigned int iLimit = 0;
cout << "Enter the Number = N = ";
cin >> iNumber;
cout << endl << "Enter the Limit = K = ";
cin >> iLimit;
unsigned long lNumber = powl(iNumber, 2);
char sNumber[50] = {NULL};
ultoa(lNumber, sNumber, 10);
int iCount = (strlen(sNumber) - iLimit);
int iLength = 0;
char sTemp[30] = {NULL};
cout << endl << "K * K = "<< lNumber << endl;
for (int i = 0; i < iCount; i ++)
{
iLength = (strlen(sNumber) - 1);
if ( (i % 2) == 0)
{
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
else
{
strrev(sNumber);
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strrev(sTemp);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
}
int iHashKey = atoi(sNumber);
cout << endl << "Hashing Key = " << iHashKey;
getch( );
return 0;
}
/************************************************************************** ************************************************************************* A C++ Program to show an example of Hashing using Mid-Square Method. ************************************************************************** **************************************************************************/
# include <iostream.h>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
# include <math.h>
int main( )
{
clrscr( );
cout << endl << "Mid-Square Hashing Method" << endl;
cout << "*************************" << endl << endl;
unsigned int iNumber = 0;
unsigned int iLimit = 0;
cout << "Enter the Number = N = ";
cin >> iNumber;
cout << endl << "Enter the Limit = K = ";
cin >> iLimit;
unsigned long lNumber = powl(iNumber, 2);
char sNumber[50] = {NULL};
ultoa(lNumber, sNumber, 10);
int iCount = (strlen(sNumber) - iLimit);
int iLength = 0;
char sTemp[30] = {NULL};
cout << endl << "K * K = "<< lNumber << endl;
for (int i = 0; i < iCount; i ++)
{
iLength = (strlen(sNumber) - 1);
if ( (i % 2) == 0)
{
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
else
{
strrev(sNumber);
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strrev(sTemp);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
}
int iHashKey = atoi(sNumber);
cout << endl << "Hashing Key = " << iHashKey;
getch( );
return 0;
}
/************************************************************************** ************************************************************************* A C++ Program to show an example of Hashing using Mid-Square Method. ************************************************************************** **************************************************************************/
# include <iostream.h>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
# include <math.h>
int main( )
{
clrscr( );
cout << endl << "Mid-Square Hashing Method" << endl;
cout << "*************************" << endl << endl;
unsigned int iNumber = 0;
unsigned int iLimit = 0;
cout << "Enter the Number = N = ";
cin >> iNumber;
cout << endl << "Enter the Limit = K = ";
cin >> iLimit;
unsigned long lNumber = powl(iNumber, 2);
char sNumber[50] = {NULL};
ultoa(lNumber, sNumber, 10);
int iCount = (strlen(sNumber) - iLimit);
int iLength = 0;
char sTemp[30] = {NULL};
cout << endl << "K * K = "<< lNumber << endl;
for (int i = 0; i < iCount; i ++)
{
iLength = (strlen(sNumber) - 1);
if ( (i % 2) == 0)
{
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
else
{
strrev(sNumber);
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strrev(sTemp);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
}
int iHashKey = atoi(sNumber);
cout << endl << "Hashing Key = " << iHashKey;
getch( );
return 0;
}
/************************************************************************** ************************************************************************* A C++ Program to show an example of Hashing using Mid-Square Method. ************************************************************************** **************************************************************************/
# include <iostream.h>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
# include <math.h>
int main( )
{
clrscr( );
cout << endl << "Mid-Square Hashing Method" << endl;
cout << "*************************" << endl << endl;
unsigned int iNumber = 0;
unsigned int iLimit = 0;
cout << "Enter the Number = N = ";
cin >> iNumber;
cout << endl << "Enter the Limit = K = ";
cin >> iLimit;
unsigned long lNumber = powl(iNumber, 2);
char sNumber[50] = {NULL};
ultoa(lNumber, sNumber, 10);
int iCount = (strlen(sNumber) - iLimit);
int iLength = 0;
char sTemp[30] = {NULL};
cout << endl << "K * K = "<< lNumber << endl;
for (int i = 0; i < iCount; i ++)
{
iLength = (strlen(sNumber) - 1);
if ( (i % 2) == 0)
{
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
else
{
strrev(sNumber);
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strrev(sTemp);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
}
int iHashKey = atoi(sNumber);
cout << endl << "Hashing Key = " << iHashKey;
getch( );
return 0;
}
/************************************************************************** ************************************************************************* A C++ Program to show an example of Hashing using Mid-Square Method. ************************************************************************** **************************************************************************/
# include <iostream.h>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
# include <math.h>
int main( )
{
clrscr( );
cout << endl << "Mid-Square Hashing Method" << endl;
cout << "*************************" << endl << endl;
unsigned int iNumber = 0;
unsigned int iLimit = 0;
cout << "Enter the Number = N = ";
cin >> iNumber;
cout << endl << "Enter the Limit = K = ";
cin >> iLimit;
unsigned long lNumber = powl(iNumber, 2);
char sNumber[50] = {NULL};
ultoa(lNumber, sNumber, 10);
int iCount = (strlen(sNumber) - iLimit);
int iLength = 0;
char sTemp[30] = {NULL};
cout << endl << "K * K = "<< lNumber << endl;
for (int i = 0; i < iCount; i ++)
{
iLength = (strlen(sNumber) - 1);
if ( (i % 2) == 0)
{
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
else
{
strrev(sNumber);
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strrev(sTemp);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
}
int iHashKey = atoi(sNumber);
cout << endl << "Hashing Key = " << iHashKey;
getch( );
return 0;
}
/************************************************************************** ************************************************************************* A C++ Program to show an example of Hashing using Mid-Square Method. ************************************************************************** **************************************************************************/
# include <iostream.h>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
# include <math.h>
int main( )
{
clrscr( );
cout << endl << "Mid-Square Hashing Method" << endl;
cout << "*************************" << endl << endl;
unsigned int iNumber = 0;
unsigned int iLimit = 0;
cout << "Enter the Number = N = ";
cin >> iNumber;
cout << endl << "Enter the Limit = K = ";
cin >> iLimit;
unsigned long lNumber = powl(iNumber, 2);
char sNumber[50] = {NULL};
ultoa(lNumber, sNumber, 10);
int iCount = (strlen(sNumber) - iLimit);
int iLength = 0;
char sTemp[30] = {NULL};
cout << endl << "K * K = "<< lNumber << endl;
for (int i = 0; i < iCount; i ++)
{
iLength = (strlen(sNumber) - 1);
if ( (i % 2) == 0)
{
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
else
{
strrev(sNumber);
strset(sTemp, NULL);
strncpy(sTemp, sNumber, iLength);
strrev(sTemp);
strset(sNumber, NULL);
strcpy(sNumber, sTemp);
}
}
int iHashKey = atoi(sNumber);
cout << endl << "Hashing Key = " << iHashKey;
getch( );
return 0;
}