C Programming code for Removing no. 1D Array – KLE Tech

Write a Modular C Programming Code for Deleting | Removing a Value from a 1D Array?

CODE:

#include<stdio.h>
void readArray(int[],int);
void delete(int A[],int n);
int main()
{
int n;
int arr[100];
printf("Enter the size of Array: ");
scanf("%d",&n);
printf("Enter the elements of array: \n");
readArray(arr,n);
delete(arr,n);
}
void readArray(int arr[],int n)
{
int i;
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
}
void displayArray(int arr[],int n)
{
int i;
for(i=0;i<n-1;i++)
{
printf("%d ",arr[i]);
}
}
void delete(int arr[],int n)
{
int i,j,pos,value;
printf("Enter the position to remove : ");
scanf("%d",&pos);
for(i=pos-1;i<n-1;i++)
arr[i]=arr[i+1];
printf("Final array after removing the value is\n");
displayArray(arr,n);}

OUTPUT

Enter the size of Array: 6
Enter the elements of array:
1
2
3
4
5
6
Enter the position to remove : 5
Final array after removing the value is
1 2 3 4 6
Process returned 0 (0x0) execution time : 6.784 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 

Leave a Comment