Click here to Skip to main content
16,022,339 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
Finally got it. Regards for the comments Mr. Sandeep Mewara mentioned things will be looked after. This is what I did

Well the problem faced here is can i transform the transposed 3-tuple representation to matrix form Row and Col

C#
#include<stdio.h>
#include<conio.h>



void main()
{
 clrscr();
 int a[10][10],b[10][10];
 int m,n,p,q,t,col;
 int i,j;
 printf("enter the no of row and columns :\n");
 scanf("%d %d",&m,&n);

 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");

 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++)
  {

  if(a[i][j]!=0)
  {
   t=t+1;
   b[t][1]=i;
   b[t][2]=j;
   b[t][3]=a[i][j];
    }  }
}

printf("\n");
printf("\n\t R   C   V \n");
printf(" \n \t%d  %d  %d \n",m,n,t);
for(i=1;i<=t;i++)
{

 printf(" \n \t%d  %d  %d \n",b[i][1],b[i][2],b[i][3]);
  }
b[0][1]=n; b[0][2]=m; b[0][3]=t;
q=1;

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][2]==i)
    {
      a[q][1]=b[j][2]; a[q][2]=b[j][1];
      a[q][3]=b[j][3]; q=q+1;
       }  }
     }  }
printf("\n\n");
printf(" %d %d %d\n",b[0][1],b[0][2],b[0][3]);
for(i=1;i<=t;i++)
{
 printf("%d %d %d\n",a[i][1],a[i][2],a[i][3]);
    }
 getch();
 }
Posted
Updated 26-Feb-11 6:44am
v2
Comments
Manfred Rudolf Bihy 25-Feb-11 9:04am    
I'm sorry, but I missed the question. Where is your question?
Sandeep Mewara 25-Feb-11 9:05am    
:)

Now, what is your doubt/issue/question here? Edit the question using 'Improve question' link and update about what you are trying here and what is stopping you.

Surely, one would help you out. Will upvote you to take my comments constructively and follow it.
OriginalGriff 25-Feb-11 9:10am    
Reason for my vote of 5: For saying thanks to Sandeep, even if it should have been in the thread with the original question! :laugh:

1 solution

Glad to see you got it!
Now, indent it sensibly, change your variable names to more descriptive ones, and comment it so that you can understand it in three weeks time! :laugh:
C#
void main()
    {
    clrscr();
    int a[10][10],b[10][10];
    int m, n, p, q, t, col;
    int i, j;
    printf("enter the no of row and columns :\n");
    scanf("%d %d", &m, &n);
    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");
    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++)
            {
            if (a[i][j] != 0)
                {
                t = t + 1;
                b[t][1] = i;
                b[t][2] = j;
                b[t][3] = a[i][j];
                }
            }
        }
    printf("\n");
    printf("\n\t R   C   V \n");
    printf(" \n \t%d  %d  %d \n", m, n, t);
    for (i = 1; i <= t; i++)
        {
        printf(" \n \t%d  %d  %d \n", b[i][1], b[i][2], b[i][3]);
        }
    b[0][1] = n;
    b[0][2] = m;
    b[0][3] = t;
    q = 1;
    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][2] == i)
                    {
                    a[q][1] = b[j][2];
                    a[q][2] = b[j][1];
                    a[q][3] = b[j][3];
                    q = q + 1;
                    }
                }
            }
        }
    printf("\n\n");
    printf(" %d %d %d\n", b[0][1], b[0][2], b[0][3]);
    for (i = 1; i <= t; i++)
        {
        printf("%d %d %d\n", a[i][1], a[i][2], a[i][3]);
        }
    getch();
    }
That's the indent done for you!


[answered to remove from unanswered list]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Feb-11 21:41pm    
Good, show them! My 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900