SlideShare a Scribd company logo
2
Most read
Array
A Menu Driven Program In C
Declarations And Main Function
#include<stdio.h>
#include<stdlib.h>
void insert(), delete_array(), display();
int array[5];
int count=-1;
int main()
{
int choice;
while(1)
{
printf("n---Array Menu---n");
printf("1. Insert.n");
printf("2. Delete.n");
printf("3. Display.n");
printf("4. Exit.n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: insert();
break;
case 2: delete_array();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("Invalid choice.");
}
}
}
Insert Function
void insert()
{
int position,data,i;
printf("Enter the position you want to insert: ");
scanf("%d",&position);
printf("Enter an integer value: ");
scanf("%d",&data);
position-=1;
if(count!=4)
{
if(position<=count+1)
{
for(i=count+1;i>position;i--)
{
array[i]=array[i-1];
}
count++;
array[position]=data;
display();
}
else
{
printf("Insertion not possible as there are only %d elements.",count+1);
}
}
else
{
printf("Array overflow");
}
}
Delete Function
void delete_array()
{
if(count==-1)
{
display();
}
else
{
int i, position, temp;
printf("Enter the position you want to delete: ");
scanf("%d",&position);
if(position-1>count)
{
printf("Deletion not possible.nAs there are no elements in this position.n");
}
else
{
temp=array[position-1];
for(i=position-1;i<=count-1;i++)
{
array[i]=array[i+1];
}
count--;
printf("The elememt deleted is %d.n",temp);
display();
}
}
}
Display Function
void display()
{
int i;
if(count==-1)
{
printf("Array is empty.");
}
else
{
printf("Elements in array: ");
for(i=0;i<=count;i++)
{
printf(" %d ",array[i]);
}
}
printf("n");
}
Presented By:-
Sayantan Sur
Thank You

More Related Content

PPTX
Lecture 12 Heuristic Searches
PPTX
STACKS IN DATASTRUCTURE
PPTX
Data Types - Premetive and Non Premetive
PPT
PHP - Introduction to File Handling with PHP
DOCX
III B.TECH CSE_flutter Lab manual (1).docx
PDF
Advanced perl finer points ,pack&amp;unpack,eval,files
PPTX
Circular link list.ppt
PPTX
Doubly & Circular Linked Lists
Lecture 12 Heuristic Searches
STACKS IN DATASTRUCTURE
Data Types - Premetive and Non Premetive
PHP - Introduction to File Handling with PHP
III B.TECH CSE_flutter Lab manual (1).docx
Advanced perl finer points ,pack&amp;unpack,eval,files
Circular link list.ppt
Doubly & Circular Linked Lists

Similar to Array menu (20)

PPTX
Stack using Array
PPTX
Single linked list
PPTX
Double linked list
PDF
Data Structure using C
PPTX
Circular linked list
PPTX
stack.pptx
DOCX
Array imp of list
PDF
C programs Set 4
DOCX
array implementation
DOCX
C program to implement linked list using array abstract data type
PPTX
Stack using Linked List
DOCX
PPTX
QueueUsingArray-1.pptxnansbsbssnsnxbxbhs
DOCX
01 list using array
DOCX
DataStructures notes
DOCX
ADA FILE
DOCX
DOCX
Chapter 8 c solution
Stack using Array
Single linked list
Double linked list
Data Structure using C
Circular linked list
stack.pptx
Array imp of list
C programs Set 4
array implementation
C program to implement linked list using array abstract data type
Stack using Linked List
QueueUsingArray-1.pptxnansbsbssnsnxbxbhs
01 list using array
DataStructures notes
ADA FILE
Chapter 8 c solution
Ad

More from Sayantan Sur (7)

PPTX
Image Encryption and Compression
PPTX
Decision Support System(DSS)
PPT
Network Security
PPT
Visual Studio IDE
PPTX
Ethical Hacking
PPT
Phising
PPT
International Terrorism
Image Encryption and Compression
Decision Support System(DSS)
Network Security
Visual Studio IDE
Ethical Hacking
Phising
International Terrorism
Ad

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Final Presentation General Medicine 03-08-2024.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
01-Introduction-to-Information-Management.pdf
Institutional Correction lecture only . . .
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
GDM (1) (1).pptx small presentation for students
A systematic review of self-coping strategies used by university students to ...
2.FourierTransform-ShortQuestionswithAnswers.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
RMMM.pdf make it easy to upload and study
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
human mycosis Human fungal infections are called human mycosis..pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS

Array menu

  • 1. Array A Menu Driven Program In C
  • 2. Declarations And Main Function #include<stdio.h> #include<stdlib.h> void insert(), delete_array(), display(); int array[5]; int count=-1; int main() { int choice; while(1) { printf("n---Array Menu---n"); printf("1. Insert.n"); printf("2. Delete.n"); printf("3. Display.n"); printf("4. Exit.n"); printf("Enter your choice: "); scanf("%d",&choice); switch(choice) { case 1: insert(); break; case 2: delete_array(); break; case 3: display(); break; case 4: exit(0); default: printf("Invalid choice."); } } }
  • 3. Insert Function void insert() { int position,data,i; printf("Enter the position you want to insert: "); scanf("%d",&position); printf("Enter an integer value: "); scanf("%d",&data); position-=1; if(count!=4) { if(position<=count+1) { for(i=count+1;i>position;i--) { array[i]=array[i-1]; } count++; array[position]=data; display(); } else { printf("Insertion not possible as there are only %d elements.",count+1); } } else { printf("Array overflow"); } }
  • 4. Delete Function void delete_array() { if(count==-1) { display(); } else { int i, position, temp; printf("Enter the position you want to delete: "); scanf("%d",&position); if(position-1>count) { printf("Deletion not possible.nAs there are no elements in this position.n"); } else { temp=array[position-1]; for(i=position-1;i<=count-1;i++) { array[i]=array[i+1]; } count--; printf("The elememt deleted is %d.n",temp); display(); } } }
  • 5. Display Function void display() { int i; if(count==-1) { printf("Array is empty."); } else { printf("Elements in array: "); for(i=0;i<=count;i++) { printf(" %d ",array[i]); } } printf("n"); }