Write a program to allocate two dimensional array with varying size of columns in C++

2. Write a program to allocate two dimensional array with varying size of columns and print in table form.
 1 2
 4 2 3
 5

#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int rw,i,j;
int **x,*c;
cout << "Enter the number of rows : ";
cin >> rw;
c= new int[rw];
cout << "\n Enter the number of column in each rows :";
for(i=0;i<rw;i++)
{
cin >> c[i];
}
for(i=0;i<rw;i++)
{

for(j=0;j<c[i];j++)
{
x[i]=new int[c[i]];
}
}
for(i=0;i<rw;i++)
{
cout << "\n Enter the vaules in "<<i+1 <<" row";
for(j=0;j<c[i];j++)
{
cin >> x[i][j];
}
}

cout << "Your array is : \n";
for(i=0;i<rw;i++)
{
for(j=0;j<c[i];j++)
{
cout << x[i][j] << " ";
}
cout << "\n";
}

delete(x);
delete(c);
getch();
return 0;

}

Comments

Popular Posts