#include <stdio.h>
int a[10], i, item, n, pos;
void Delete_beg(){
n--;
for ( i = 0; i < n; i++)
{
a[i]=a[i+1];
}
}
void Delete_end(){
n--;
}
void Delete_pos(){
printf("\nEnter the position for deletion: ");
scanf("%d", &pos);
for (i = pos; i < n - 1; i++)
{
a[i] = a[i + 1];
}
n--;
}
void display(){
printf(" After Delete Your elements are: ");
for (i = 0; i < n; i++)
{
printf(" %d ", a[i]);
}
}
int main()
{
printf("---- Welcome to Deletion of element from array ----");
printf("\n 1. Press 1 for Delete element at the beginning ");
printf("\n 2. Press 2 for Delete element at the end ");
printf("\n 3. Press 3 for Delete element at the any position ");
int c;
scanf("%d",&c);
printf("Enter the length of the Array: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("Your elements are: ");
for (i = 0; i < n; i++)
{
printf(" %d ", a[i]);
}
switch (c)
{
case 1:
Delete_beg();
display();
break;
case 2:
Delete_end();
display();
break;
case 3:
Delete_pos();
display();
break;
default:
break;
}
return 0;
}
Comments
Post a Comment