-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercise(2).c
131 lines (119 loc) · 2.26 KB
/
Exercise(2).c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
Program using ARRAY
AUTHOR: Mohit Hooda
Create a character array B of size 15. Write functions to perform the following
operations on the array
a)Insert element into array next to the last occupied.
b)Delete the first inserted element.
c)Check if the array is completely occupied.
d)Check if the array is empty.
e)Display the content of the array
Write a main program to insert two more elements into the array B, delete 5
elements, and check the empty and full conditions of the array. After each
insertion and deletion operation display the contents of the array
Sample Array B=[A,B,C,D,E,F,G,H,I,J]
After calling function insert(P) B=[A,B,C,D,E,F,G,H,I,J,P]
After calling function delete b) B=[B,C,D,E,F,G,H,I,J,P]
*/
#include<stdio.h>
int insert(char a[],int size)
{
printf("\nEnter the alphabet you want to ENTER : ");
char num;
scanf(" %c",&num);
a[size]=num;
size++;
int i;
printf("Array is: \n");
for(i=0;i<size;i++)
{
printf("%c\t",a[i]);
}
return size;
}
int delete(char a[],int size)
{
printf("The first number is getting deleted from array.......deleted !");
int i;
for(i=1;i<size;i++)
{
a[i-1]=a[i];
}
printf("\nArray is:\n");
a[size]=0;
size--;
for(i=0;i<size;i++)
{
printf("%c \t",a[i]);
}
return size;
}
void checkEmpty(char a[],int size)
{
if(size==0)
{
printf("Yes,It is empty!\n");
return;
}
else
{
printf("No,It is not empty!\n");
return;
}
}
void checkFull(char a[],int size)
{
if(size==15)
{
printf("Yes,It is FULL!\n");
return;
}
else
{
printf("No,It is not FULL!\n");
return;
}
}
void displayArray(char a[],int size)
{
printf("Array is :\n");
int i;
for(i=0;i<size;i++)
{
printf("%c\t",a[i]);
}
}
int main()
{
char a[]={'a','b','c','d','e','f','g','h','i','j'};
int size=10;
char c;
printf("Hello! You want to try anything....\na.Insert \nb.Delete\nc.Check Full \nd.Check Empty\ne.Display array\no.For Exit \n\n");
scanf("%c",&c);
while(c!='o')
{
if(c=='a')
{
size=insert(a,size);
}
else if(c=='b')
{
size=delete(a,size);
}
else if(c=='c')
{
checkFull(a,size);
}
else if(c=='d')
{
checkEmpty(a,size);
}
else if(c=='e')
{
displayArray(a,size);
}
printf("\nWant to try something new :");
scanf("%c",&c);
}
return 0;
}