this is my code I am using in Unix machine, using cc compiler:
#include<stdlib.h>
main()
{
int nr=0,nc=0;
printf("Enter number of coulmns:");
scanf("%d",&nc);
printf("Enter number of rows:");
scanf("%d",&nr);
int *x,temp;
printf("Enter the matrix:\n");
for(int i=0;i<nr;i++)
{
for(int j=0;j<nc;j++)
{
scanf("%d",&temp);
*(x+i*nc+j)=temp;
}
}
for(int i=0;i<nr;i++)
{
for(int j=0;j<nc;j++)
{
printf("%d ",*(x+i*nc+j));
}
printf("\n");
}
}
It takes number of rows and number of coulmns properly. But, I am getting core as soon as I enter first integer input to the matrix. Can anybody tell me what is the problem?