#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int array[50], size, i, element, count=0;
printf("Enter array size : ");
scanf("%d",&size);
printf("Enter array elements : ");
for(i=0; i<size; i++)
{
scanf("%d",&array[i]);
}
printf("Enter element to be delete : ");
scanf("%d",&element);
for(i=0; i<size; i++)
{
if(array[i]==element)
{
for(int j=i; j<(size-1); j++)
{
array[j]=array[j+1];
}
count++;
break;
}
}
if(count==0)
{
printf("Element not found..!!");
}
else
{
printf("Element deleted successfully..!!\n");
printf("Now the new array is :\n");
for(i=0; i<(size-1); i++)
{
printf("%d ",array[i]);
}
}
getch();
}
Run1:
Run2:
Previous Next
#include<conio.h>
void main()
{
clrscr();
int array[50], size, i, element, count=0;
printf("Enter array size : ");
scanf("%d",&size);
printf("Enter array elements : ");
for(i=0; i<size; i++)
{
scanf("%d",&array[i]);
}
printf("Enter element to be delete : ");
scanf("%d",&element);
for(i=0; i<size; i++)
{
if(array[i]==element)
{
for(int j=i; j<(size-1); j++)
{
array[j]=array[j+1];
}
count++;
break;
}
}
if(count==0)
{
printf("Element not found..!!");
}
else
{
printf("Element deleted successfully..!!\n");
printf("Now the new array is :\n");
for(i=0; i<(size-1); i++)
{
printf("%d ",array[i]);
}
}
getch();
}
Run1:
Run2:
Previous Next
No comments:
Post a Comment