Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Practical File of Data Structure (D.

S) for
Batch 2021-2024 BTech (LE) CSE

Data
Structure
Lab File 2021 - 2024

Gaurav Kumar Jha


B.Tech (LE) CSE
Name: Gaurav Kumar Jha
Branch: LE CSE 2021-2024

Experiment 1
__________________________________________________________________________________

AIM 1: WAP to Insert array at the Beginning of 1D Array.


Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int a[100],n,i,item;
clrscr();
printf("Gaurav Kumar Jha CSE");
printf("enter size of Array:");
scanf("%d",&n);
printf("enter element in Array");
for(i=0;i<5;i++)
{ scanf("%d",&a[i]);
}
printf("insert element in Array at beggining");
scanf("%d",&item);
n++;
for(i=n; i>1;i--)
{ a[i-1]=a[i-2];
}
a[0]=item;
printf("resulting Array:");
for(i=0;i<n;i++)
{
printf("%d",a[i]);
}
getch();
}

Output
Name: Gaurav Kumar Jha
Branch: LE CSE 2021-2024

AIM 2: WAP to Insert array at the End of 1D Array.

Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[10], i, element;
printf("Enter 5 Array Elements: ");
printf("Garav Kumar Jha CSE");
for(i=0; i<5; i++)
scanf("%d", &arr[i]);
printf("\nEnter Element to Insert: ");
scanf("%d", &element);
arr[i] = element;
printf("\nThe New Array is:\n");
for(i=0; i<6; i++)
printf("%d ", arr[i]);
getch();
return 0;

Output :
Name: Gaurav Kumar Jha
Branch: LE CSE 2021-2024

AIM 2: WAP to Insert array at the specific location of 1D


Array.

Code:
#include<stdio.h>
#include<conio.h>
int main() { clrscr();
int array[10], position,c,n,value;
printf("Gaurav Kumar Jha CSE");
printf("enter no of element in array\n");
scanf("%d",&n);
printf("enter %d elements\n",n);
for(c=0;c<n;c++)
scanf("%d", &array[c]);
printf("enter the location where you wish to insert an element\n");
scanf("%d",&position);
printf("enter the value to insert\n");
scanf("%d" ,&value);
for(c=n-1;c>=position-1;c--)
array[c+1]=array[c];
array[position-1]=value;
printf("resaulting array is\n");
for(c=0;c<=n;c++)
printf("%d\n", array[c]);
getch();
}

Output :

You might also like