Here is the code..
/*AIM: DELETION OF A ELEMENT FROM ARRAY*/
#include<stdio.h>
void deletion(int[] ,int,int);
void main()
{
int n,pos,a[10],i;
printf("enter no of elements for array length 10\n");
scanf("%d",&n);
if(n==0)
{
printf(" CAN NOT PERFORM DELETION");
}
else
{
printf("enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("given array is\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
printf("enter the position of deletion\n");
scanf("%d",&pos);
deletion(a ,n ,pos);
}
}
void deletion(int a[10],int n,int pos)
{
int i,t;
t = a[pos-1];
for(i=pos;i<n;i++)
{
a[i-1]=a[i];
}
n = n-1;
printf("deleted element is %d\n",t);
printf("array after deletion is\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
For Turbo C users.
/*AIM: DELETION OF A ELEMENT FROM ARRAY*/
#include<stdio.h>
#include<conio.h>
void deletion(int[] ,int,int);
void main()
{
int n,pos,a[10],i;
clrscr();
printf("enter no of elements for array length 10\n");
scanf("%d",&n);
if(n==0)
{
printf(" CAN NOT PERFORM DELETION");
}
else
{
printf("enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("given array is\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
printf("enter the position of deletion\n");
scanf("%d",&pos);
deletion(a ,n ,pos);
}
getch();
}
void deletion(int a[10],int n,int pos)
{
int i,t;
t = a[pos-1];
for(i=pos;i<n;i++)
{
a[i-1]=a[i];
}
n = n-1;
printf("deleted element is %d\n",t);
printf("array after deletion is\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
No comments:
Post a Comment