/**
Program Name: LINEAR SEARCH
Description: This program finds a given Item in an Array
Author: Tauqirul Haque
*/
#define SIZE 5
void linearSearch(int data[], int item);
void displayElement(int data[]);
void main()
{
int data[SIZE] = { 56,34,75,24,76};
int item;
int choice;
while(choice != 3)
{
printf("\n\t\t 1. Search an Item ");
printf("\n\t\t 2. Display The Elements ");
printf("\n\t\t 3. Quit the Program");
printf("\n\n\t\t Enter Your Choice # ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the Element you want to Search # ");
scanf("%d",&item);
linearSearch(data,item);
break;
case 2:
displayElement(data);
break;
case 3:
printf("Program Terminated ... \n");
getch();
exit(0);
}
}
}
void linearSearch(int data[SIZE], int item)
{
int i;
for(i=0;i
{
if(item == data[i])
{
printf("\nSEARCH SUCCESSFULL # Location = %d \n\n",i+1);
return;
}
}
printf("\nSearch UNSUCCESSFULL ... Item Not in the List\n");
}
void displayElement(int data[SIZE])
{
int i;
for(i=0; i
{
printf("\n Data[%d] = %d ", i+1, data[i]);
}
printf("\n");
}
Program Name: LINEAR SEARCH
Description: This program finds a given Item in an Array
Author: Tauqirul Haque
*/
#define SIZE 5
void linearSearch(int data[], int item);
void displayElement(int data[]);
void main()
{
int data[SIZE] = { 56,34,75,24,76};
int item;
int choice;
while(choice != 3)
{
printf("\n\t\t 1. Search an Item ");
printf("\n\t\t 2. Display The Elements ");
printf("\n\t\t 3. Quit the Program");
printf("\n\n\t\t Enter Your Choice # ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the Element you want to Search # ");
scanf("%d",&item);
linearSearch(data,item);
break;
case 2:
displayElement(data);
break;
case 3:
printf("Program Terminated ... \n");
getch();
exit(0);
}
}
}
void linearSearch(int data[SIZE], int item)
{
int i;
for(i=0;i
{
if(item == data[i])
{
printf("\nSEARCH SUCCESSFULL # Location = %d \n\n",i+1);
return;
}
}
printf("\nSearch UNSUCCESSFULL ... Item Not in the List\n");
}
void displayElement(int data[SIZE])
{
int i;
for(i=0; i
{
printf("\n Data[%d] = %d ", i+1, data[i]);
}
printf("\n");
}
Comments