Hi,I have tried to get this program to work,but it works to the moment when you enter some of the array`s numbers and then crashes.In different sizes of the matrix you can enter different number of numbers,but for instance when the matrix is 5x5 the program crashes after the 11th number,if the matrix is 9x9 crashes after 18th, if the matrix is 4x5 crashes after the 11th ,and 5x4 on the 9th.I think I have made the "for" loops right and I hope the problem is that I don`t know something rather than a stupid mistake.
I would love to recieve any help.
#include <iostream.h>
#include <stdio.h>
int** matrij;
void matrin(int i,int j)//Can I replace i and j with rows and cols here?
{
cout<<"Enter the matrix number by number.\n";
int a,b;
for(a=0;a<i;a++)
for(b=0;b<j;b++)
scanf("%d",&matrij[a][b]);
}
void matrout(int i,int j)
{
int a,b;
for(a=0;a<i;a++){
for(b=0;b<j;b++)
printf("%d ",matrij[a][b]);
cout<<"\n";
}
}
main()
{
int cols,rows;
cout<<"MATRIX V0.1\n";
cout<<"Enter the number of rows and then the number of columns of the matrix.\n";
cin>>rows>>cols;
matrij=new int*[cols*rows];
matrin(rows,cols);
matrout(rows,cols);
delete[] matrij;
matrij=0;
system("pause");
return 0;
}