Array | C Program
else
printf("\n");
#include<stdio.h>
#include<conio.h>
main()
{
int
a[15],i,p,n; //p=position, n=size of array
clrscr();
printf("Enter No. of elements in Array: ");
scanf("%d",&n);
printf("\nEnter elements of Array: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nThe elements of Array: ");
for(i=0;i<n;i++) //for print
original array
printf("%d\t",a[i]);
//for delete position
printf("\n\nEnter Position No of elements for delete: ");
scanf("%d",&p);
if(p>n)
{
printf("\n\t\t**Invalid Position Number**\n");
printf("\nElements of Array-\n\n"); //updated array
for(i=0;i<n;i++)
printf("%d\t",a[i]);
}
else
{
for(i=p-1;i<n-1;i++)
a[i]=a[i+1];
printf("\nUpdated Array:\n\n"); //updated array
for(i=0;i<n-1;i++)
printf("%d\t",a[i]);
}
printf("\n");
getch();
}
OUTPUT:
OUTPUT:
C Program to delete an element in an array |
0 Comments
Please do not enter any spam link in the comment box.