Array Deletion
Array Deletion
#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);
// after deletion
printf ("The elements of array is:\n");
for (i = 0; i < size; i++)
{
printf ("%d\t",a[i]);
}
return 0;
}
#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--;
// after deletion
printf ("The elements of array is:\n");
for (i = 0; i < size; i++)
{
printf ("%d\t", a[i]);
}
return 0;
}
#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--;
// after deletion
printf ("The elements of array is:\n");
for (i = 0; i < size; i++)
{
printf ("%d\t", a[i]);
}
return 0;
}