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

Array C

The document contains C code for inserting and deleting elements in an array. It defines functions for insertion and deletion, and demonstrates their usage in the main function. The code includes commented-out sections for additional functionality and user input for testing the operations.

Uploaded by

Misna
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)
49 views3 pages

Array C

The document contains C code for inserting and deleting elements in an array. It defines functions for insertion and deletion, and demonstrates their usage in the main function. The code includes commented-out sections for additional functionality and user input for testing the operations.

Uploaded by

Misna
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/ 3

#include <stdio.

h>

void insert(int pos , int elm , int a[10], int *len)


{
int i;
for(i=*len; i>pos ; i--)
{
a[i]=a[i-1];
}
a[pos]=elm;
(*len)++;

void delete(int a[10], int *len, int pos)


{
int i;
for(i=pos;i<*len-1; i++)
{
a[i] = a[i+1];

}
(*len)--;

int main()
{

int a[10]={1,2,3,4,5};
int pos, elm, len=5;
int i;

/*
printf("enter pos and elm");
scanf("%d %d",&pos, &elm);

insert(pos, elm, a, &len);

printf("Array after insertion:\n");


for(i=0;i<len;i++)
{
printf("%d ",a[i]);
}
*/

printf("enter pos");
scanf("%d", &pos);
delete(a, &len, pos);

printf("Array after deletion:\n");


for ( i = 0; i < len; i++) {
printf("%d ", a[i]);
}

return 0;
}
/*

#include <stdio.h>

int arr[10] = {1, 2, 3, 4, 5};


int n = sizeof(arr) / sizeof(arr[0]);

void insert(int pos) {


for (int i = n; i >pos; i--) {
arr[i ] = arr[i-1];
}
arr[pos ] = 14;
n++;

int main() {
insert(2);

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


printf("%d\n", arr[i]);
}

return 0;
}
*/

You might also like