Friday, August 27, 2010

C Program to delete an element from array


#include<stdio.h>
#include<conio.h>
int i,n;
main()
{
int a[100],pos;
void del(int a[],int,int);
clrscr();
printf("\n How many elements in the array \n");
scanf("%d",&n);
printf("\n Enter the element of the array \n");
for(i=0;i<=n;i++)
scanf("%d",&a[i]);
printf("\n On which position element do you want to delete \n");
scanf("%d",pos);
del(a,pos,num);
getch();
}

void del(int a[],int pos,int n)
{
int j,item;
item=a[pos];
for(j=pos;j<=n-1;j++)
{
a[j]=a[j+1];
}
n=n-1;
printf(" New Array \n");
for(i=0;i<=n-1;i++)
printf(" %d\n",a[i]);
}

No comments:

Post a Comment