//Insertion Of a Column in 2D Array
#include<iostream.h>
#include<conio.h>
main()
{
int i,j,k,m,n;
int a[10][10];
int b[10];
cout<<"Enter Dimensions of array";
cin>>m>>n;
cout<<"Enter Elements";
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
{cin>>a[i][j];}}
cout<<"Enter Column no Where to insert";
cin>>k;
cout<<"Enter a column to Insert";
for(i=1;i<=m;i++)
{cin>>b[i];}
//Shifting
n=n+1;
for(i=1;i<=m;i++)
{for(j=n;j>=k;j--)
{a[i][j]=a[i][j-1];}}
//insertion
for(i=1;i<=m;i++)
{a[i][k]=b[i];}
//printing
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
{cout<<a[i][j];}
cout<<endl;}
getch();
}
#include<iostream.h>
#include<conio.h>
main()
{
int i,j,k,m,n;
int a[10][10];
int b[10];
cout<<"Enter Dimensions of array";
cin>>m>>n;
cout<<"Enter Elements";
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
{cin>>a[i][j];}}
cout<<"Enter Column no Where to insert";
cin>>k;
cout<<"Enter a column to Insert";
for(i=1;i<=m;i++)
{cin>>b[i];}
//Shifting
n=n+1;
for(i=1;i<=m;i++)
{for(j=n;j>=k;j--)
{a[i][j]=a[i][j-1];}}
//insertion
for(i=1;i<=m;i++)
{a[i][k]=b[i];}
//printing
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
{cout<<a[i][j];}
cout<<endl;}
getch();
}
No comments:
Post a Comment