Delete element in 2d array
This is a Program which first accept input from user and then ask the user for place where he want to delete the element in two dimensional array.delete two dimensional array c++
delete two dimensional array
Program to delete in Array
#include "stdafx.h"#include "iostream"
#include "conio.h"
using namespace std;
int main()
{
int a[3][3]={{1,2,3,},{4,5,6},{7,8,9}};
int row,coulmn,j,i;
cout<<"matrix elements are== ";
for(int i=0;i<3;i++)
{cout<<endl;
for(int j=0;j<3;j++)
{
cout<<a[i][j]<<"\t";
}
}
cout<<"\n\n"<<"Enter row== ";
cin>>row;
cout<<"\n\n"<<"Enter coulmn== ";
cin>>coulmn;
for( i=row;i<=2;i++)
{
for( j=coulmn;j<=2;j++)
{
a[i][j]=a[i][j+1];
if(i==2 && j==2)
a[i][j]=0;
}
coulmn=0;
}
for(i=0;i<=2;i++)
{
for( j=0;j<=2;j++)
{
cout<<a[i][j];
cout<<"\t";
}
cout<<"\n";
}
getch();
return 0;
}
0 comments:
Post a Comment