0% found this document useful (0 votes)
67 views5 pages

Insert A Particular Element in A Specified Position On C Programming.

Insert a particular element in a specified position on C programming use for university documentation and publications. Thanks and regards, Mosabbir Ahamed

Uploaded by

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

Insert A Particular Element in A Specified Position On C Programming.

Insert a particular element in a specified position on C programming use for university documentation and publications. Thanks and regards, Mosabbir Ahamed

Uploaded by

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

C program to insert a particular element in a specified

position:

#include <stdio.h>

#include<conio.h>

void main()

int array[10];

int i, j, n, m, temp, key, pos;

printf("Enter how many elements \n");

scanf("%d", &n);

printf("Enter the elements \n");

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

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

printf("Input array elements are \n");

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

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

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

for (j = i + 1; j < n; j++)

if (array[i] > array[j])

temp = array[i];
array[i] = array[j];

array[j] = temp;

printf("Sorted list is \n");

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

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

printf("Enter the element to be inserted \n");

scanf("%d", &key);

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

if (key < array[i])

pos = i;

break;

if (key > array[n-1])

pos = n;

break;

if (pos != n)

m = n - pos + 1 ;

for (i = 0; i <= m; i++)

array[n - i + 2] = array[n - i + 1] ;
}

array[pos] = key;

printf("Final list is \n");

for (i = 0; i < n + 1; i++)

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

OUTPUT:
C program to delete an element from an array
#include <stdio.h>

#include <conio.h>

int main()

int array[100], position, c, n;

printf("Enter number of elements 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 delete element\n");

scanf("%d", &position);

if ( position >= n+1 )

printf("Deletion not possible.\n");

else

for ( c = position - 1 ; c < n - 1 ; c++ )

array[c] = array[c+1];

printf("Resultant array is\n");

for( c = 0 ; c < n - 1 ; c++ )

printf("%d\n", array[c]);

return 0;

}
OUTPUT:

You might also like