#include <stdio.h>
#include <stdlib.h>
int main ()
{
int k;
int aux;
int size = 8;
int x[8] = {2, 3, 5, 7, 11, 13, 17, 19};
scanf("%d",&k);
aux = x[k];
for (int i = k; i < size - 1; i++)
x[i] = x[ i + 1];
x[ size - 1] = aux;
for (int i = 0; i < size; i++)
printf("%d ", x[i]);
}
change this program to
Write a program to remove an element from an array at the given position k and push the rest of the array elements one position back. Then insert the removed element at the beginning. Position k is entered through keyboard. For example, if the original array x is {'r', 'c', 'm', '7', 'w', '3', 'q'} and k = 3, the array will be changed to {'7', 'r', 'c', 'm', 'w', '3', 'q'}.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int k;
int aux;
int position;
int size = 8;
int x[8] = {2, 3, 5, 7, 11, 13, 17, 19};
scanf("%d",&k);
aux = x[k];
for (int i = k; i < size - 1; i++)
x[i] = x[ i + 1];
x[ size - 1] = aux;
for (int i = 0; i < size; i++)
printf("%d ", x[i]);
printf("Enter the location where you wish to delete element\n"); scanf("%d", &position);
if ( position >size) printf("Deletion not possible.\n"); else { for ( i = position - 1 ; i < size - 1 ; i++ ) x[i] = x[i+1];
}
x_splice($input, 0, 0);
printf("%d ", x[i]);
}
Get Answers For Free
Most questions answered within 1 hours.