Repository navigation
Expand file tree
/
Copy pathP3.c
More file actions
58 lines (58 loc) · 1.66 KB
/
Copy pathP3.c
File metadata and controls
58 lines (58 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>
int main()
{
int a[50], n, i, j, pos, item, ch,temp;
printf("Enter size : ");
scanf("%d", &n);
printf("Enter elements : ");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
do
{
printf("\n 1.Insert\n 2.Delete\n 3.Search\n 4.Sort\n 5.Display\n 6.Exit");
printf("\nEnter choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter position and item : ");
scanf("%d%d",&pos,&item);
for(i=n; i>=pos;i--)
a[i] = a[i-1];
a[pos-1] = item;
n++;
break;
case 2: printf("Enter position : ");
scanf("%d",&pos);
for(i=pos-1; i<n-1; i++)
a[i] = a[i+1];
n--;
break;
case 3: printf("Enter item : ");
scanf("%d",&item);
for(i=0; i<n; i++)
if(a[i]==item)
break;
if(i<n)
printf("Found at position %d", i+1);
else
printf("Not Found");
break;
case 4: for(i=0; i<n-1; i++)
for(j=0; j<n-i-1; j++)
if(a[j]>a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
printf("Sorted");
break;
case 5: for(i=0; i<n; i++)
printf("%d ",a[i]);
break;
case 6: break;
default : printf("Invalid Choice");
}
}while(ch!=6);
return 0;
}