#include<stdio.h>
#include<stdlib.h>
int
SEARCH(int
LA[100], int
N);
int
INSERT(int
LA[100], int
N);
int
SHOW(int
LA[100], int
N);
int
main()
{
int
LA[100],i, N;
char
ch;
printf("\nEnter how many
array element: ");
scanf("%d",
&N);
printf("\nEnter array
elements:\n");
for(i=0;i<N;i++)
{
printf("\nElement
no %d: ",
i+1);
scanf("%d",
&LA[i]);
}
menu:
{
printf("\nSelect your
operation:\n")
;
printf("\n1: SEARCH an item");
printf("\n2: INSERT an
element ");
printf("\n0: Exit\n ")
do{
ch=getche();
switch
(ch) {
case
'1':
SEARCH(LA, N);
break;
case
'2':
INSERT(LA, N);
break;
case
'0':
return
0 ;
default:
printf("\nWRONG option seleted \n\nPlease
select Correct
Key: ");
}
}while(ch!='1'
&& ch!='2'&&
ch!='0');
}
goto
menu;
return
0;
}
int
SEARCH(int
LA[100], int
N)
{
int
item,i=0, LOC=0;
printf("\nSearch ITEM:
");
scanf("%d",
&item);
while(i!=N)
{
if(LA[i]==item)
{
LOC=i+1;
printf("\nITEM
location: %d",
LOC);
break;
}
i++;
}
if(i==N
&& LOC==0)
printf("\nITEM is not
existed !!!!!");
return
0;
}
int
INSERT(int
LA[100], int
N)
{
int
item, LOC, i;
printf("\nInserting ITEM: ");
scanf("%d",
&item);
printf("\nInsearting
Location: ");
scanf("%d",&LOC);
for(i=N-1;
i>=LOC-1; i--)
LA[i+1]=LA[i];
LA[LOC-1]=item;
SHOW(LA, N+1);
return
0;
}
int
SHOW(int
LA[100], int
N)
{
int
i;
printf("\LINEAR ARRAY:\n");
for(i=0;
i<N; i++)
printf("\t%d",
LA[i]);
return
0;
}
|
Program of Searching and inserting a item in a linear array - using function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment