0% found this document useful (0 votes)
6 views2 pages

Exp 1

3

Uploaded by

handearyan40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Exp 1

3

Uploaded by

handearyan40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*---Delete an element into one dimensional array---*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,x,c,pos,n;
clrscr();
printf("Enter no. of elements");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter element no %d\t",i+1);
scanf("%d",&a[i]);
}
printf("\n Arary is:");
for(i=0;i<n;i++)
{
printf("\n Element no %d\t%d",i+1,a[i]);
}
printf("\n Eneter element to be deleted:");
scanf("%d",&x);
for(i=0;i<n;i++)
{
if(a[i]==x)
{
c=1;
pos=i;
break ;
}
}
if(c==1)
{
for (i=pos;i<n;i++)
a[i]=a[i+1];
printf("Array after deletion \n");
for(i=0;i<n-1;i++)
{
printf("\n Element no %d\t%d",i+1,a[i]);
}
}
else
{
printf("Element was not found.....");
}
getch();
}
/* -----OUTPUT-----*/
/*
Enter no. of elements 4
Enter element no 1 12
Enter element no 2 78
Enter element no 3 89
Enter element no 4 45

Arary is:
Element no 1 12
Element no 2 78
Element no 3 89
Element no 4 45
Eneter element to be deleted:45
Array after deletion

Element no 1 1245
Element no 2 78
Element no 3 89*/

You might also like