Delete an element at desired position from an array.
#include<stdio.h>
int main() {
int a[10];
int n, i, j, x;
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter the elements : ");
for (i=0; i<n; i++){
scanf("%d",&a[i]);
}
printf("Enter the desired position where you want to delete element : ");
scanf("%d",&x);
for (i=x; i<n-1; i++){
a[i]=a[i+1];
}
for (i=0; i<n-1; i++){
printf("%d ",a[i]);
}
return 0;
}
Output:-
Enter the number of elements : 5
Enter the elements : 12 58 74 32 15
Enter the desired position where you want to delete element : 3
12 58 74 15
No comments:
Post a Comment