0% found this document useful (0 votes)
8 views3 pages

Array Deletion

Uploaded by

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

Array Deletion

Uploaded by

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

//At specific position

#include <stdio.h>

int main ()
{
int a[50], i, size, pos, item;
printf ("Enter the size of the array:\n");
scanf ("%d", &size);
printf ("Enter the elements in array:\n");
for (i = 0; i < size; i++)
{
scanf ("%d", &a[i]);
}

// before deletion
printf ("The elements of array is:\n");
for (i = 0; i < size; i++)
{
printf ("%d\t",a[i]);
}

printf("\n");
printf ("Form which position you want to delete the data:\n");
scanf ("%d", &pos);

if (pos <= 0 || pos > size)


{
printf ("Invalid position!!");
}
else
{
item = a[pos - 1];
for (i = pos - 1; i < size - 1; i++)
{
a[i] = a[i + 1];
}
size--;
}
printf ("The deleted data iem is : %d\n", item);

// after deletion
printf ("The elements of array is:\n");
for (i = 0; i < size; i++)
{
printf ("%d\t",a[i]);
}

return 0;
}

//Deletion from begening

#include <stdio.h>

int main ()
{
int a[50], i, size, item;
printf ("Enter the size of the array:\n");
scanf ("%d", &size);
printf ("Enter the elements in array:\n");
for (i = 0; i < size; i++)
{
scanf ("%d", &a[i]);
}

// before deletion
printf ("The elements of array is:\n");
for (i = 0; i < size; i++)
{
printf ("%d\t", a[i]);
}

printf ("\n");

item = a[0];
for (i = 0; i < size - 1; i++)
{
a[i] = a[i + 1];
}
size--;

printf ("The deleted data iem is : %d\n", item);

// after deletion
printf ("The elements of array is:\n");
for (i = 0; i < size; i++)
{
printf ("%d\t", a[i]);
}

return 0;
}

//deletetion at end of the array

#include <stdio.h>

int main ()
{
int a[50], i, size, item;
printf ("Enter the size of the array:\n");
scanf ("%d", &size);
printf ("Enter the elements in array:\n");
for (i = 0; i < size; i++)
{
scanf ("%d", &a[i]);
}

// before deletion
printf ("The elements of array is:\n");
for (i = 0; i < size; i++)
{
printf ("%d\t", a[i]);
}

printf ("\n");

item = a[size-1];
// for (i = 0; i < size - 1; i++)
// {
// a[i] = a[i + 1];
// }
size--;

printf ("The deleted data iem is : %d\n", item);

// after deletion
printf ("The elements of array is:\n");
for (i = 0; i < size; i++)
{
printf ("%d\t", a[i]);
}

return 0;
}

You might also like