Académique Documents
Professionnel Documents
Culture Documents
Ans:
#include<stdio.h>
int a[100],n;
void create(void);
void insert(void);
void delet(void);
void search(void);
void maxmin(void);
void ascending(void);
void descending(void);
void display(void);
int main(void)
{
int i;
create();
do
{
printf("\n\n\n1 for INSERT an element\n2 for DELETE an element\n3 for Search an
element\n4 for Find Maximum and Minimum element\n5 for Sort in Ascending order\n6 for Sort in
Descending Order\n7 for display the Array\n8 for EXIT");
printf("\n\nEnter the above option:");
scanf("%d",&i);
switch(i)
{
case 1:
insert();
break;
case 2:
delet();
break;
case 3:
search();
break;
case 4:
1
maxmin();
break;
case 5:
ascending();
break;
case 6:
descending();
break;
case 7:
display();
break;
case 8:
break;
default:
printf("\n\t*****Sorry*****\n\tYour Entered Input is wrong\n\tPlease,
Try Again");
}
}while(i!=8);
}
void insert(void)
{
int i=n-1,p,v;
printf("\nEnter the Position of the array:");
scanf("%d",&p);
if(p<=(n-1))
{
printf("\nEnter the new element (number) of this position:");
scanf("%d",&v);
p-=1;
n+=1;
while(i>=p)
{
a[i+1]=a[i];
i-=1; //i--;
}
a[p]=v;
printf("\n\n%d is Inserted in the ARRAY",v);
}
else
printf("\n\nYou Enter wrong position.\n........Try again........");
}
void create(void)
{
int i;
printf("\nEnter how many elements you want to enter:");
scanf("%d",&n);
printf("\n.....Enter the Array element one by one.....\n");
for(i=0;i<n;i++)
{
printf("Enter the element no %d:",i+1);
scanf("%d",&a[i]);
}
2
void delet(void)
{
int p,i;
printf("\nEnter the Position of the array:");
scanf("%d",&p);
if(p<=(n-1))
{
i=p;
printf("\n%d element is deleted from ARRAY\n\n",a[p-1]);
while(i<=(n-1))
{
a[i-1]=a[i];
i++;
}
n=n-1;
}
else
printf("\n\nYou enter wrong position.\n........Try again........");
}
void search(void)
{
int num,i,flag=0,po;
printf("\nEnter the element for searching purpose:");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(a[i]==num)
{
po=i;
flag++;
}
}
if(flag==0)
printf("\nGiven number is not present in the Array");
else
{
printf("\nGiven number is present in the array with %d time(s)",flag);
printf("\nPosition is %d",po+1);
}
}
3
void maxmin(void)
{
int max=a[0],min=a[0],i=0;
while(i<n)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
i++;
}
printf("\nMaximum element is %d",max);
printf("\nMinimum element is %d",min);
}
void ascending(void)
{
int i=0,j,b[100],temp;
for(i=0;i<n;i++)
b[i]=a[i];
i=0;
while(i<n)
{
j=i+1;
while(j<n)
{
if(b[i]>b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
j++;
}
i+=1;
}
printf("\n\nAfter ascending.......\n");
for(i=0;i<n;i++)
printf("\n %d",b[i]);
}
void descending(void)
{
int i=0,j,b[100],temp;
for(i=0;i<n;i++)
b[i]=a[i];
i=0;
while(i<n)
4
{
j=i+1;
while(j<n)
{
if(b[i]<b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
j++;
}
i+=1;
}
printf("\n\nAfter descending.......\n");
for(i=0;i<n;i++)
printf("\n %d",b[i]);
}
void display(void)
{
int i;
for(i=0;i<n;i++)
printf("\nElement of position %d is %d",i+1,a[i]);
}
OUTPUT:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc array.c -o array
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./array
Enter how many elements you want to enter:5
.....Enter the Array element one by one.....
Enter the element no 1:25
Enter the element no 2:45
Enter the element no 3:12
Enter the element no 4:96
Enter the element no 5:87
...The above Array is...
Element no 1 is 25
Element no 2 is 45
Element no 3 is 12
Element no 4 is 96
Element no 5 is 87
1 for INSERT an element
2 for DELETE an element
3 for Search an element
4 for Find Maximum and Minimum element
5
suvranshu@suvranshu-desktop:~/Desktop/Student$
10
Output:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc matrix.c -o matrix
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./matrix
Enter no. of rows:3
Enter no. of collumns:4
Enter the element for the position 1 & 1: 15
Enter the element for the position 1 & 2: 25
Enter the element for the position 1 & 3: 87
Enter the element for the position 1 & 4: 45
Enter the element for the position 2 & 1: 36
Enter the element for the position 2 & 2: 95
Enter the element for the position 2 & 3: 10
Enter the element for the position 2 & 4: 58
Enter the element for the position 3 & 1: 69
Enter the element for the position 3 & 2: 36
Enter the element for the position 3 & 3: 89
11
if(flag==0)
printf("\nGiven number is not present in the Array");
else
{
printf("\nGiven number is present in the array with %d time(s)",flag);
printf("\nPosition is row:%d, col=%d",por+1,poc+1);
}
return 0;
}
3. Write a program in C to transpose a given matrix. Matrix Order & Elements are given by
user.
Ans:
#include<stdio.h>
int main(void)
{
int m[10][10],r,c,i,j;
printf("\nEnter no. of rows:");
scanf("%d",&r);
printf("\nEnter no. of collumns:");
scanf("%d",&c);
printf("\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("Enter the element for the position %d & %d: ",i+1,j+1);
scanf("%d",&m[i][j]);
}
}
printf("\n\n.....Given Matrx is.....\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d ",m[i][j]);
}
printf("\n");
}
printf("\n\n.....After transporation.....\n");
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
{
printf("%d ",m[j][i]);
}
printf("\n");
}
return 0;
}
13
OUTPUT:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc mtranspose.c -o trans
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./trans
Enter no. of rows:3
Enter no. of collumns:4
Enter the element for the position 1 & 1: 2
Enter the element for the position 1 & 2: 5
Enter the element for the position 1 & 3: 8
Enter the element for the position 1 & 4: 4
Enter the element for the position 2 & 1: 3
Enter the element for the position 2 & 2: 6
Enter the element for the position 2 & 3: 9
Enter the element for the position 2 & 4: 1
Enter the element for the position 3 & 1: 2
Enter the element for the position 3 & 2: 5
Enter the element for the position 3 & 3: 6
Enter the element for the position 3 & 4: 4
.....Given Matrx is.....
2 5 8 4
3 6 9 1
2 5 6 4
.....After transporation.....
2 3 2
5 6 5
8 9 6
4 1 4
suvranshu@suvranshu-desktop:~/Desktop/Student$
4. Write a program in C to multiplication of two matrices. Result is store in another matrix.
Matrix Order & Elements are given by user.
Ans:
#include<stdio.h>
int main(void)
{
int a[20][20],b[20][20],c[20][20],r1,c1,r2,c2,i,j,k;
printf("\n.....Details of 1st matrix.....");
printf("\nEnter the No. of rows:");
scanf("%d",&r1);
printf("Enter the no. of column:");
scanf("%d",&c1);
printf("\n");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
{
printf("Enter the element for the position %d & %d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
14
15
OUTPUT:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc multiplication.c -o mul
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./mul
.....Details of 1st matrix.....
Enter the No. of rows:2
Enter the no. of column:3
Enter the element for the position 1 & 1: 4
Enter the element for the position 1 & 2: 2
Enter the element for the position 1 & 3: -1
Enter the element for the position 2 & 1: 3
Enter the element for the position 2 & 2: -7
Enter the element for the position 2 & 3: 1
.....Details of 2nd matrix.....
Enter the No. of rows:3
Enter the no. of column:2
Enter the element for the position 1 & 1: 2
Enter the element for the position 1 & 2: 3
Enter the element for the position 2 & 1: -3
Enter the element for the position 2 & 2: 0
Enter the element for the position 3 & 1: -1
Enter the element for the position 3 & 2: 5
.....Given 1st Matrx is.....
4 2 -1
3 -7 1
.....Given 2nd Matrx is.....
2 3
-3 0
-1 5
.....After Multiplication.....
3 7
26 14
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./mul
.....Details of 1st matrix.....
Enter the No. of rows:3
Enter the no. of column:3
Enter the element for the position 1 & 1: 1
Enter the element for the position 1 & 2: 2
Enter the element for the position 1 & 3: 3
Enter the element for the position 2 & 1: 4
Enter the element for the position 2 & 2: 5
Enter the element for the position 2 & 3: 6
Enter the element for the position 3 & 1: 7
Enter the element for the position 3 & 2: 8
16
17
STRING
1. Write a program in C, to find the length of a String.
Ans:
Using Array:
#include<stdio.h>
int main(void)
{
char n[25];
int l=0;
printf("\nEnter any String:");
gets(n); //scanf() function not taking Space
while(n[l]!=0)
{
l=l+1;
}
printf("\n\nThe string '%s' contains %d Characters\n",n,l);
return 0;
}
//(or) while(s[c]!=NULL)
18
Using Pointer:
#include<stdio.h>
int main(void)
{
char a[50];
char *p;
int len=0;
printf("\nEnter a string:");
gets(a);
p=a;
//(or)p=&a[0]
while(*p!='\0')
{
len++;
p++;
}
printf("\nLength of the '%s' string is %d\n",a,len);
return 0;
}
19
OUTPUT:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc slen_arr.c -o slen_arr
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./slen_arr
Enter any String:Computer science
The string 'Computer science' contains 16 Characters
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./slen_arr
Enter any String:h.s.
The string 'h.s.' contains 4 Characters
suvranshu@suvranshu-desktop:~/Desktop/Student$
20
Using Array:
#include<stdio.h>
int main(void)
{
char s[25],t[25];
int l=0;
printf("\nEnter a String:");
gets(s);
while(s[l]!='\0')
{
t[l]=s[l];
l++;
}
t[l]='\0';
printf("\n\nSource String:%s",s);
printf("\nTarget string:%s\n",t);
return 0;
}
Using pointer:
#include<stdio.h>
int main(void)
{
char s[20],t[20];
char *p1,*p2;
printf("\nEnter a String:");
gets(s);
p1=s;
//(or)p1=&a[0]
p2=t;
while(*p1!='\0')
{
*p2=*p1;
p1++;
p2++;
}
*p2='\0';
printf("\nSource string is %s",s);
printf("\nTarget string is %s\n",t);
return 0;
}
22
OUTPUT:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc scpy_arr.c -o scpy_arr
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./scpy_arr
Enter a String:Computer
Source String:Computer
Target string:Computer
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./scpy_arr
Enter a String:Learn
Source String:Learn
Target string:Learn
suvranshu@suvranshu-desktop:~/Desktop/Student$
3. Write a program in C to concatenate two strings.
Ans:
Using Pointer:
#include<stdio.h>
int main(void)
{
char source[50],target[50];
char *p1,*p2;
printf("\nEnter a Source string:");
gets(source);
printf("\nEnter the Target string:");
gets(target);
p1=source;
p2=target;
while(*p2!='\0')
{
p2++;
}
while(*p1!='\0')
{
*p2=*p1;
p1++;
p2++;
}
*p2='\0';
printf("\nSource String is %s",source);
printf("\nTarget String is %s\n",target);
return 0;
}
23
24
4. Write a program in C to convert a string upper to lower or lower to upper. (as user choice)
Ans:
#include<stdio.h>
#include<stdlib.h>
void upp_low(char *);
void low_upp(char *);
int main(void)
{
char a[200];
int i;
printf("Enter a String:");
gets(a);
while(1)
{
printf("\nPress 1 for transfer the string UPPER to LOWER\nPress 2 for transfer the
string LOWER to UPPER\nPress 3 for Exit");
printf("\n\nEnter the above option:");
scanf("%d",&i);
switch(i)
{
case 1:
upp_low(a);
printf("\n.....After Lower case transfer.....\nString is %s\n\n",a);
break;
case 2:
low_upp(a);
printf("\n.....After Upper case transfer.....\nString is %s\n\n",a);
break;
case 3:
exit(1);
default:
printf("\n\t*****Sorry*****\n\tYour Entered Input is wrong\n\tPlease,
Try Again");
}
}
return 0;
}
void upp_low(char *s)
{
while(*s!='\0')
{
if((*s>=65)&&(*s<=90))
{
*s=*s+32;
}
s++;
}
*s='\0';
}
25
26
Using Pointer:
#include<stdio.h>
int main(void)
{
char a[200];
char *p;
printf(Enter a String:);
gets(a);
p=a;
while(*p!=\0)
{
if((*p>=65)&&(*p<=90))
{
*p=*p+32;
}
p++;
}
*p=\0;
printf(\n..After Lower case transfer..\nString is %s,a);
p=a;
while(*p!=\0)
{
if((*p>=97)&&(*p<=122))
{
*p=*p-32;
}
p++;
}
*p=\0;
printf(\n\n..After Upper case transfer..\nString is %s\n,a);
return 0;
}
OUTPUT:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc scase1.c -o scase1
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./scase1
Enter a String:Computer Science
.....After Lower case transfer.....
String is computer science
.....After Upper case transfer.....
String is COMPUTER SCIENCE
suvranshu@suvranshu-desktop:~/Desktop/Student$
28
Ans:
Using pointer:
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[100],b[100];
char *p1,*p2;
int l1,l2,i=0,d;
printf("Enter the 1st string:");
gets(a);
printf("Enter the 2 nd String:");
gets(b);
p1=a;
p2=b;
l1=strlen(a);
l2=strlen(b);
if(l1<l2)
{
l1=l1+l2;
l2=l1-l2;
l1=l1-l2;
}
i=0;
while(i<l1)
{
if(*p1!=*p2)
{
d=*p1-*p2;
break;
}
p1++;
p2++;
i+=1;
}
printf("\nDifference between above two string\n'%s'-'%s'=%d\n",a,b,d);
return 0;
}
29
OUTPUT:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc scmp.c -o scmp
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./scmp
Enter the 1st string:Jerry
Enter the 2 nd String:Jerry
Difference between above two string
'Jerry'-'Jerry'=0
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./scmp
Enter the 1st string:Jerry
Enter the 2 nd String:Ferry
Difference between above two string
'Jerry'-'Ferry'=4
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./scmp
Enter the 1st string:Jerry
Enter the 2 nd String:Jerry Boy
Difference between above two string
'Jerry'-'Jerry Boy'=-32
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./scmp
Enter the 1st string:JERRY
Enter the 2 nd String:JeRry
Difference between above two string
'JERRY'-'JeRry'=-32
suvranshu@suvranshu-desktop:~/Desktop/Student$
7. Write a program in C to print a string in reverse order. (Ex. INDIA AIDNI)
Ans:
Using Pointer:
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[200],b[100];
char *p1,*p2;
int l,i=0;
printf("Enter a String:");
gets(a);
p1=a;
p2=b;
l=strlen(a);
p1=p1+(l-1);
i=0;
while(i<l)
{
*p2=*p1;
p2++;
p1--;
i+=1;
31
}
*p2='\0'
;
printf("\n.....After Reverse.....");
printf("\nOriginal String %s",a);
printf("\nReverse String %s\n",b);
return 0;
}
Using pointer with sub function:
#include<stdio.h>
void reverse(char *,char *);
int str_len(char *);
int main(void)
{
char a[200],b[100];
printf("Enter a String:");
gets(a);
reverse(a,b);
printf("\n.....After Swap.....");
printf("\nOriginal String %s",a);
printf("\nReverse String %s\n",b);
return 0;
}
void reverse(char *x,char *y)
{
int l,i=0;
l=str_len(x);
x=x+(l-1);
while(i<l)
{
*y=*x;
y++;
x--;
i+=1;
}
*y='\0';
}
int str_len(char *s)
{
int l=0;
while(*s!='\0')
{
l++;
s++;
}
return l;
}
32
Using array:
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[200],b[100];
int l,i,d,k=0;
printf("Enter a String:");
gets(a);
l=strlen(a);
k=0;
for(i=l-1;i>=0;i--)
{
b[k]=a[i];
k++;
}
b[k]='\0';
printf("\n.....After Reverse.....");
printf("\nOriginal String %s",a);
printf("\nReverse String %s\n",b);
d=strcmp(a,b);
if(d==0)
printf("\nThe string '%s' is palindrom\n",a);
else
printf("\nThe string '%s' is NOT palindrom\n",a);
return 0;
}
Using Pointer:
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[200],b[100];
char *p1,*p2;
int l,i=0,d;
printf("Enter a String:");
gets(a);
p1=a;
p2=b;
l=strlen(a);
p1=p1+(l-1);
i=0;
while(i<l)
{
*p2=*p1;
p2++;
p1--;
i+=1;
33
}
*p2='\0';
printf("\n.....After Reverse.....");
printf("\nOriginal String %s",a);
printf("\nReverse String %s\n",b);
d=str_cmp(a,b);
if(d==0)
printf("\nThe string '%s' is palindrom\n",a);
else
printf("\nThe string '%s' is NOT palindrom\n",a);
return 0;
}
34
35
STACK
1. Write a program in C to accept a stack (using Array) and perform the following operation:
i. PUSH an Element,
ii. POP an Element,
iii. Display the Stack.
All operation should be in separate function. Size of stack will be user defined. The entire system
will be menu-driven.
Ans:
#include<stdio.h>
int a[100],n,top=-1;
void push(void);
void pop(void);
void display(void);
int main(void)
{
int i;
printf("\nEnter the Size of of the STACK:");
scanf("%d",&n);
do
{
printf("\n\n\n1 for PUSH\n2 for POP\n3 for DISPLAY\n4 for EXIT");
printf("\n\nPress the key of the above option:");
scanf("%d",&i);
switch(i)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
break;
default:
printf("\n\t*****Sorry*****\n\tYour Entered Input is wrong\n\tPlease,
Try Again");
}
}while(i!=4);
return 0;
}
36
void push(void)
{
int i;
if(top==(n-1))
printf("\n\n\t***The Stack is OVER FLOWED***\n\t No element can be PUSH");
else
{
top++;
printf("\nEnter the number:");
scanf("%d",&i);
a[top]=i;
printf("\n\n%d is PUSH in the Stack",i);
}
}
void pop(void)
{
if(top==-1)
printf("\n\n\t***The Stack is UNDER FLOWED***\n\t So No element can be POP");
else
{
printf("\n\n%d is POP from the Stack",a[top]);
top=top-1;
}
}
void display(void)
{
int i;
if(top==-1)
printf("\n\n\t***The Stack is UNDERFLOWED***");
else
{
printf("\n|--------|");
for(i=top;i>=0;i--)
{
printf("\n %d",a[i]);
printf("\n|--------|");
}
}
}
OUTPUT:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc stack.c -o stack
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./stack
Enter the Size of of the STACK:4
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
37
|--------|
36
|--------|
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
Enter the number:87
87 is PUSH in the Stack
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
Enter the number:95
95 is PUSH in the Stack
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
***The Stack is OVER FLOWED***
No element can be PUSH
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
|--------|
95
|--------|
87
39
|--------|
10
|--------|
36
|--------|
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
95 is POP from the Stack
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
|--------|
87
|--------|
10
|--------|
36
|--------|
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
87 is POP from the Stack
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
10 is POP from the Stack
40
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
|--------|
36
|--------|
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
36 is POP from the Stack
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
***The Stack is UNDER FLOWED***
So No element can be POP
1 for PUSH
2 for POP
3 for DISPLAY
4 for EXIT
Press the key of the above option:4
suvranshu@suvranshu-desktop:~/Desktop/Student$
41
QUEUE
1. Write a program in C to accept a Queue (using Array) and perform the following operation:
a. Insertion,
b. Deletion,
c. Display
All operation should be in separate function. Size of Queue will be user defined. The entire
system will be menu-driven.
Ans:
#include<stdio.h>
int q[100],n,front=-1,rear=-1;
void qinsert(void);
void qdelete(void);
void qdisplay(void);
int main(void)
{
int i;
printf("\nEnter the Size of of the QUEUE:");
scanf("%d",&n);
do
{
printf("\n\n\n1 for Insert\n2 for DELETE\n3 for DISPLAY\n4 for EXIT");
printf("\n\nPress the key of the above option:");
scanf("%d",&i);
switch(i)
{
case 1:
qinsert();
break;
case 2:
qdelete();
break;
case 3:
qdisplay();
break;
case 4:
break;
default:
printf("\n\t*****Sorry*****\n\tYour Entered Input is wrong\n\tPlease,
Try Again");
}
}while(i!=4);
return 0;
}
42
void qinsert(void)
{
int item;
if((front==0&&rear==(n-1))||(front==rear+1))
printf("\n\n\t***The Queue is Full***\n\t No element can be iserted");
else
{
if(front==-1)
{
front=0;
rear=0;
}
else if(rear==n-1)
rear=0;
else
rear=rear+1;
printf("\nEnter the value:");
scanf("%d",&item);
q[rear]=item;
printf("\n%d is inserted",item);
}
}
void qdelete(void)
{
int item;
if(front==-1)
printf("\n\n\t***The Queue is Empty***\n\t So No element can be deleted");
else
{
item=q[front];
if(front==rear)
{
front=-1;
rear=-1;
}
else if(front==n-1)
front=0;
else
front=front+1;
printf("\n%d is deleted",item);
}
}
void qdisplay(void)
{
int i;
if(rear==-1)
printf("\n\n\t***The Queue is Empty***");
else
{
if(rear>=front)
for(i=front;i<=rear;i++)
printf("%d ",q[i]);
43
else
{
for(i=front;i<=n-1;i++)
printf("%d ",q[i]);
for(i=0;i<=rear;i++)
printf("%d ",q[i]);
}
}
}
OUTPUT:
suvranshu@suvranshu-desktop:~/Desktop/Student$ gcc queue.c -o queue
suvranshu@suvranshu-desktop:~/Desktop/Student$ ./queue
Enter the Size of of the QUEUE:5
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
***The Queue is Empty***
So No element can be deleted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
***The Queue is Empty***
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
Enter the value:10
10 is inserted
1 for Insert
44
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
Enter the value:20
20 is inserted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
Enter the value:30
30 is inserted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
10 20 30
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
10 is deleted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
20 30
1 for Insert
2 for DELETE
3 for DISPLAY
45
4 for EXIT
Press the key of the above option:1
Enter the value:40
40 is inserted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
Enter the value:50
50 is inserted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
Enter the value:60
60 is inserted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
***The Queue is Full***
No element can be iserted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
20 is deleted
46
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
30 40 50 60
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
30 is deleted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
40 is deleted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
50 60
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:1
Enter the value:70
70 is inserted
1 for Insert
2 for DELETE
3 for DISPLAY
47
4 for EXIT
Press the key of the above option:1
Enter the value:80
80 is inserted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
50 60 70 80
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
50 is deleted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
60 is deleted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
70 is deleted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
48
80
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
80 is deleted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:3
***The Queue is Empty***
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:2
***The Queue is Empty***
So No element can be deleted
1 for Insert
2 for DELETE
3 for DISPLAY
4 for EXIT
Press the key of the above option:4
suvranshu@suvranshu-desktop:~/Desktop/Student$
49