Site icon T4Tutorials.com

Program to delete selected array elements in C++ (CPP, C Plus Plus) and C with flowchart

Program to delete selected array elements in C++ (CPP, C Plus Plus) and C with flowchart

In this tutorial, we will learn about the followings;

  1. Flowchart of a program to delete the selected array elements 
  2. Program to delete the selected array elements in C++
  3. Program to delete the selected array elements in C

Flowchart of a program to delete the selected array elements 

Coming Soon.

Program to delete the selected array elements in C++

#include<iostream>
#include<conio.h>
using namespace std;
int main()
  {
   int j;
   int array[5];
   int no;
   int position;
   cout<<"Enter data in array: "<<endl;  
   // code for data entry in array using for loop
   for(j=0;j<5;j++)
   {
    cin>>array[j];
   }
   cout<<"\n\nData shown in array:  ";  
    // code for displaying the data
   for(j=0;j<5;j++)
   {
    cout<<array[j];
   }
   cout<<"\n\nEnter position of element to delete: ";        
   // enter thevindexor position to delete a value from the array 
   cin>>position;
   if(position>5)
   {
   cout<<"\n\nThis value is not in the array: ";
   }
   else
   {
   --position;
   for(j=position;j<=4;j++)
   {
    array[j]=array[j+1];
   }
   cout<<"\n\nNew data after deletion in array is: ";                  
    //new array display after required number is deleted
   for(j=0;j<4;j++)
   {
    cout<<array[j];
  }
  }
  
   getch();
   return 0;
 }

Output

program to delete selected array elements in C++, C plus plus, C
Figure: program to delete selected array elements in C++, C Plus Plus, C.

Program to delete the selected array elements in C

#include<stdio.h>
#include<conio.h>

int main()
{
	//clrscr();
 int j;
 int array[5];
 int no;
 int position;
 
 printf("Enter data in array: ");
 for(j=0;j<5;j++)
 {
 scanf("%d",&array[j]);
 }
 printf("\n\n Data shown in array: ");
 for(j=0;j<5;j++)
 {
 printf("  %d",array[j]);
 }
 printf("\n\nEnter position of number: ");
 scanf("%d",&position);
 if(position>5)
 {
 printf("\n\nThis value is not in the array ");
 }
 else
 {
 --position;
 for(j=position;j<=4;j++)
 {
 array[j]=array[j+1];
 }
 printf("\n\nNew data after deletion in array is: ");
 for(j=0;j<4;j++)
 {
 printf("  %d",array[j]);
 }
 }
 getch();
 return 0;
}

Output

program to delete selected array elements in C++, C plus plus, C
Figure: program to delete selected array elements in C++, C Plus Plus, C.

YouTube video player

Exit mobile version