Life Hacks


      

Write a program of the deletion in an array.



#include<iostream.h>

#include<conio.h>

void main( ) /* main start */

{

clrscr( );

int a[20], j, n, k, b, c, item; /* local variable */

cout << " \n Enter the number of elements in an array is : " << " \n ";

cin >> n;

cout << " \n Enter the value of elements of array is : " << " \n ";

for(c = 1; c <= n; c++)

{

cin>>a[c];

} /* End of for */

cout << " \n Enter the position of element in which is deleted: "<< " \n ";

cin >> k;

item = a[c];

for(j = k; j <= n – 1; j++)

{

a[ j ] = a[ j+1 ];

} /* End of for */

n = n – 1;

cout << " \n Now new array is : " << " \n ";

for(c = 1; c <= n; c ++)

{

cout << " \n " << a[c];

} /* End of for */

getch( );

}

Output:-

clip_image002

Leave a Reply