100% found this document useful (1 vote)
44 views4 pages

Exp1. Program To Perform Operations On Array.

The document contains a C program that performs operations on arrays. It defines functions to create, display, insert, and delete elements from an array. The main function uses a menu to call these functions and allows the user to choose an operation to perform. The functions implement the operations to dynamically create, access, and modify the array elements as directed by the user.

Uploaded by

Sujal Bokariya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
44 views4 pages

Exp1. Program To Perform Operations On Array.

The document contains a C program that performs operations on arrays. It defines functions to create, display, insert, and delete elements from an array. The main function uses a menu to call these functions and allows the user to choose an operation to perform. The functions implement the operations to dynamically create, access, and modify the array elements as directed by the user.

Uploaded by

Sujal Bokariya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

/* Exp1. Program to perform operations on array.

*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int a[20],b[20],c[40];
int m,n,p,val,i,j,key,pos,temp;
/*Function Prototype*/
void create();
void display();
void insert();
void del();
int main()
{

int choice;
do
{
printf("\n\n--------Menu-----------\n");
printf("1.Create\n");
printf("2.Display\n");
printf("3.Insert\n");
printf("4.Delete\n");
printf("5.Exit\n");
printf("-----------------------");
printf("\nEnter your choice:\t");
scanf("%d",&choice);
switch(choice)
{
case 1: create();
break;
case 2: display();
break;
case 3: insert();
break;
case 4: del();
break;
case 5: exit(0);
break;
default: printf("\nInvalid choice:\n");
break;
}
}while(choice!=5);
return 0;
}
void create() //creating an array
{
printf("\nEnter the size of the array elements:\t");
scanf("%d",&n);
printf("\nEnter the elements for the array:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}//end of create()

void display() //displaying an array elements


{
int i;
printf("\nThe array elements are:\n");
for(i=0;i<n;i++){
printf("%d\t",a[i]);
}
}//end of display()

void insert() //inserting an element in to an array


{
printf("\nEnter the position for the new element:\t");
scanf("%d",&pos);
printf("\nEnter the element to be inserted :\t");
scanf("%d",&val);
for(i=n-1;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=val;
n=n+1;
}//end of insert()

void del() //deleting an array element


{
printf("\nEnter the position of the element to be deleted:\t");
scanf("%d",&pos);
val=a[pos];
for(i=pos;i<n-1;i++)
{
a[i]=a[i+1];
}
n=n-1;
printf("\nThe deleted element is =%d",val);
}//end of delete()

/*OUTPUT*/

--------Menu-----------
1.Create
2.Display
3.Insert
4.Delete
5.Exit
-----------------------
Enter your choice: 1
Enter the size of the array elements: 3

Enter the elements for the array:


5 10 15

--------Menu-----------
1.Create
2.Display
3.Insert
4.Delete
5.Exit
-----------------------
Enter your choice: 2

The array elements are:


5 10 15

--------Menu-----------
1.Create
2.Display
3.Insert
4.Delete
5.Exit
-----------------------
Enter your choice: 3

Enter the position for the new element: 1

Enter the element to be inserted: 20

--------Menu-----------
1.Create
2.Display
3.Insert
4.Delete
5.Exit
-----------------------
Enter your choice: 2

The array elements are:


5 10 15 20

--------Menu-----------
1.Create
2.Display
3.Insert
4.Delete
5.Exit
-----------------------
Enter your choice: 4
Enter the position of the element to be deleted: 2

The deleted element is =10

--------Menu-----------
1.Create
2.Display
3.Insert
4.Delete
5.Exit
-----------------------
Enter your choice: 2

The array elements are:


5 15 20

--------Menu-----------
1.Create
2.Display
3.Insert
4.Delete
5.Exit
-----------------------
Enter your choice:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy