0% found this document useful (0 votes)
6 views2 pages

Array Operations in C Programming

The document contains code for an array program with functions to create, display, insert into and delete from the array. The main function uses a switch case to call the appropriate function based on the user's choice.

Uploaded by

shravya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Array Operations in C Programming

The document contains code for an array program with functions to create, display, insert into and delete from the array. The main function uses a switch case to call the appropriate function based on the user's choice.

Uploaded by

shravya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <stdio.

h>
#include<stdlib.h>
int a[100], i, choice, element, position, n, deleted;
void create ()
{
printf ("enter the size\n");
scanf ("%d", &n);
printf ("enter the elements\n");
for (i = 0; i < n; i++)
scanf ("%d", &a[i]);
}

void display ()
{
printf ("array elements:\n");
for (i = 0; i < n; i++)
printf ("%d\t", a[i]);
}

void insert ()
{
printf ("enter the position\n");
scanf ("%d", &position);
if (position < 0 || position >= n)
printf ("invalid\n");
else
{
printf("enter the element\n");
scanf("%d",&element);
for(i=n-1;i>=position;i--)
a[i+1]=a[i];
a[position]=element;
n=n+1;
}
}
void delete()
{
printf ("enter the position\n");
scanf ("%d", &position);
deleted=a[position];
if (position < 0 || position >= n)
printf ("invalid\n");
else
{
for(i=position;i<n-1;i++)
a[i]=a[i+1];
n=n-1;
printf("deleted element is %d",deleted);
}
}
void main()
{
while(1)
{
printf("\nMENU\[Link]\[Link]\[Link]\[Link]\t5,exit\n");
printf("enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:create();
break;
case 2:display();
break;
case 3:insert();
break;
case 4:delete();
break;
case 5:exit(0);
default:printf("invalid\n");
}
}
}

You might also like