1. ## transpose sparse matrix

Hello to all This is my firts post and topic here and also I'm new and starter in C++

as you see in topic title here is the code of transpose of sparse matrix
can anyone tell me completely what does program do line by line

i have an another easy algorithm but want to know how this works and anyone knows another way to find transpose of this matrix , its good to have it in topic

thanks a lot

Code:
```#include<stdio.h>
#include<conio.h>

// transpose for the sparse matrix

void main()
{
clrscr();
int a,b;
int m,n,p,q,t,col;
int i,j;

printf("enter the no of row and columns :\n");
scanf("%d %d",&m,&n);

// assigning the value of matrix

for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("a[%d][%d]= ",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\n\n");

//displaying the matrix

printf("\n\nThe matrix is :\n\n");

for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}

t=0;

printf("\n\nthe non zero value matrix are :\n\n");

for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{

// accepting only non zero value
if(a[i][j]!=0)
{
t=t+1;
b[t]=i;
b[t]=j;
b[t]=a[i][j];
}  }
}

// displaying the matrix of non-zero value

printf("\n");
printf("a[0 %d %d %d\n",m,n,t);

for(i=1;i<=t;i++)
{
printf("a[%d %d %d %d \n",i,b[i],b[i],b[i]);
}

b=n; b=m; b=t;
q=1;

// transpose of the matrix

printf("\n\nthe transpose of the matrix :\n ");

if(t>0)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=t;j++)
{
if(b[j]==i)
{
a[q]=b[j]; a[q]=b[j];
a[q]=b[j]; q=q+1;
}  }
}    }

printf("\n\n");
printf("a[0 %d %d %d\n",b,b,b);

for(i=1;i<=t;i++)
{
printf("a[%d %d %d %d\n",i,a[i],a[i],a[i]);
}
getch();
}``` 2. First of all, this is 'C' code and not 'C++'.

Second of all, you're never going to learn how to program by copy/pasting code from the internet.

Finally, I don't think anyone here is going to explain this to you comprehensively line by line. That would take a long time, and probably wouldn't help you much if you don't understand anything about the language anyway.

If learning to program is your goal, how about you start with a simple "hello world" program (that you write by yourself)? There are links for tutorials at the top if this very page. 3. How is it you have those code but no idea how it works? Tell us what you do understand.
If the answer to that is nothing I would suggest the c++ tutorial on this website first.

Looks like matt beat me to it! 4. You need to show some effort, so here's how it goes:
You tell us what you think each line means, then we'll tell you if you are right. If you can't be bothered doing that, then you can understand why we cant be bothered either. Popular pages Recent additions 