I think I can help, but please keep in mind that whenever you right programs you have 2 basic audiences, the computer and people who will try to understand your code and maintain it in the future. In this regard the biggest problem is that you need to indent your code so people can understand what you intended it to mean.
From the computer's perspective, the biggest problem is that the computer does not know how big the array 'x' is when you pass it into the routine 'sparse()'.
Let's explore how the computer handles memory for an array. In a computer memory is linear, meaning that memory is really just one long list of numbers, with each number having a location in the list called its address. In order to represent a two dimensional array, the compiler puts the first row in the first part of memory, the second row in the next part, etc.. What this means is, for example, an array which is 2 by 3, or to use code
myArray[2][3]
will have two rows of 3 values each. Let's say the array's first row has the values 1, 2, and 3 in it and the second row has the values 4, 5, and 6 in it. In this case, the memory within the computer will look like this: 1, 2, 3, 4, 5, 6.
When we write an expression such as
int sample = myArray[1][2];
the compiler must compute the correct address of memory from the coordinates given by using its knowledge of the size of the array. In this case, the compiler knows each row is 3 long, so the memory location being accessed is 1 * 3 + 2, or the 5th memory location within the memory for the array. (Don't forget that arrays are zero-based, meaning that the first row is row number zero.) Thus, in this example, 'sample' will be set to 5.
Now we come to the core problem, from the computer's perspective, in your code: because you have not told the compiler in your definition of 'sparse()' how big the array is, the compiler cannot know what math it should do to compute the addresses of each element of the array.
One simple fix, which is not recommended, is to tell the compiler how big the array is when passing it into 'sparse()', in both locations. This not recommended because when passing arrays into a function the values are copied, which in this case is a waste of time. There is also a limit in some systems on how much data can be passed into a routine.
If this is just a quick test program, and will not need to be maintained in the future, the simplest solution is to make the array 'x' a global by putting it outside the 'main()' line, then not passing it into the 'sparse()' routine at all.
There are other issues with your code, for example, it appears that sp[][], which you define with 200 rows of 200 columns, will never have more than the first 3 column used. And from a readability standpoint, my personal rule is to never use single letter variables because they are hard to understand what their meaning is supposed to be.
At any rate, I hope my ramblings are instructional, though I have left much up to you to continue debugging. Below is a version of your code, indented for readability, with 'x' made global so 'sparse()' can use it.
#include <stdio.h>
#include <conio.h>
int x[100][100];
void main()
{
int r,c,i,j;
void sparse(int r,int c);
printf("Enter the no of rows :");
scanf("%d",&r);
printf("Enter the no of columns :");
scanf("%d",&c);
for(i=0;i<r;i++)>
{
for(j=0;j<c;j++)>
{
scanf("%d",&x[i][j]);
}
}
sparse(r,c);
getch();
}
void sparse(int r,int c)
{
int sp[200][200];
int m,n,k=1;
for(m=0;m<r;m++)>
{
for(n=0;n<c;n++)>
{
if(x[m][n]!=0)
{
sp[k][0]=m+1;
sp[k][1]=n+1;
sp[k][2]=x[m][n];
k++;
}
}
}
sp[0][0]=r;
sp[0][1]=c;
sp[0][2]=k-1;
printf("The sparse matrix is :\n");
for(m=0;m<k;m++)>
{
for(n=0;n<3;n++)
{
printf("%d\t",sp[m][n]);
}
}
}