Non-Recursive C Program:
Aim:
To delete a element in a array.
Program:
#include<stdio.h>
#include<conio.h>
void main ( )
{
int A[25],m,i,num,flag;
printf("\nEnter the size of array:");
scant("%d",&m);
printf("\nEntet the Elements:");
for(i=0;i<m;i++)
{
scanf("%d",&A[i]);
}
printf("\nThe Array is:");
for(i=0;i<m;i++)
{
printf("%3d",A[i]);
}
printf("\nEnter the Element to be deleted from Array:");
scant("%d",&num);
for(i=0;i<m;i++)
{
if( A[i]==num )
{
flag=1;
pos=i;
break;
}
}
if( flag==1 )
{
for( i=pos;i<m-1;i++)
{
A[i] = A[i+1];
}
printf("\nDeletion is possible and After Deletion");
for( i=0;i<m-1;i++)
{
printf("%d\t",A[i]);
}
}
else
printf("\nDeletion is not possible");
}
No comments:
Post a Comment