Delete an element at a Specified Position in a given Array

Random Post

#include<stdio.h>

int insert(int [], int, int);

int main()

{

int i,n,num,pos;

printf("Enter the number of elements: ");

scanf("%d",&n);

int arr[n];

printf("\nEnter the values below: \n");

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

{

printf("\nElement [%d] : ",i+1);

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

}

printf("\nEnter the element you want to delete: ");

scanf("%d",&num);

insert(arr, n, num);

}

int insert(int a[], int n, int num)

{

int i,pos;

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

{

if(a[i]==num)

pos=i;

}

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

{

a[i]=a[i+1];

}

printf("The array after deletion of element is: ");

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

{

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

}

return 0;

}

9 views

Recent Posts

See All

"Believe you can and you're halfway there"