Hi,
I've been trying to compile the following code in visual c++ 2010 Express Edition.
But the output window just says:
1>------ Build started: Project: Ans7, Configuration: Debug Win32 ------
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code Follows:
/*Program to dynamically allocate a 2D array*/
#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
void printmat(int **p,int m,int n)
{
int i,j;
//Print Full Matrix:
cout<<"The full Matrix is:\n";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
cout<<p[i][j]<<" ";
}
//print the lower matrix:
cout<<"The Lower Triangle is\n";
for(i=0;i<m;i++)
{
cout<<endl;
for(int j=0;j<n;j++)
{
if(i<j)
break;
else
cout<<p[i][j]<<" ";
}
}
}
void main()
{ //clrscr();
int **p,m,n,i,j;
cout<<"Enter the no of Rows: ";
cin>>m;
cout<<"Enter the no of Columns: ";
cin>>n;
//Dynamic allocation of 2D array:
p=new int*[m];
for(i=0;i<m;i++)
p[i]=new int[n];
//Taking I\P:
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("Enter p[%d][%d]: ",i,j);
scanf("%d",&p[i][j]);
}
}
printmat(p,m,n);
getch();
}