0% found this document useful (0 votes)
2 views3 pages

Data Structure Lab 5

The document provides a C program that allows users to insert elements into an array. It prompts for the size of the array, the elements to be inserted, and the index at which to insert a new element. The program also includes validation for array size and index before performing the insertion and displays the updated array afterward.

Uploaded by

Tamal Barua
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
0% found this document useful (0 votes)
2 views3 pages

Data Structure Lab 5

The document provides a C program that allows users to insert elements into an array. It prompts for the size of the array, the elements to be inserted, and the index at which to insert a new element. The program also includes validation for array size and index before performing the insertion and displays the updated array afterward.

Uploaded by

Tamal Barua
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

Excrement No 3 : Write and Execute programmers for inserting and deleting elements

of array .

#include <stdio.h>

#define MAX_SIZE 100

int main(){

int array[MAX_SIZE],size,element, index;

printf("Enter the size of the array (up to %d ):", MAX_SIZE);

scanf("%d",&size);

if (size <= 0 || size >MAX_SIZE){

printf("Invalid array size.\n");

return 0;

printf("Erten the Element of the array :\n");

for(int i = 0; i< size ; i++){

scanf("%d",&array[i]);

printf("Enter the element of insert : ");

scanf("%d", &element);

printf("Enter the element of insert : ");

scanf("%d", &index);

if (index <0 || index > size){

printf("Invalid index.\n");

return 0;

for (int i = size -1; i >= index; i--)

array[i + 1]= array[i];

array[index]=element;
array[index]=element;

size++;

printf("Array after insertion:");

for (int i = 0; i < size; i++)

printf("%d",array[i]);

printf("\n");

return 0;

You might also like