This program allows you to delete an element at any position in an integer array
/* http://native-code.blogspot.com */ #include<stdio.h> #include<conio.h> #define MAX 20 void del_from_array(int [], int, int); void main() { int a[MAX], i, pos, max; printf("/* http://native-code.blogspot.com */ \n\nEnter maximum range:\n"); scanf("%d", &max); printf("\nEnter elements:\n"); for(i=0; i<max; i++) scanf("%d", &a[i]); printf("\nEnter position:\n"); scanf("%d", &pos); del_from_array(a, pos, max); getch(); } void del_from_array(int a[], int pos, int max) { int i; pos=pos-1; for(i=pos; i<max; i++) a[i]=a[i+1]; for(i=0; i<max-1; i++) printf("%d ", a[i]); } /* http://native-code.blogspot.com */
Post a Comment