Click here to Skip to main content
12,949,601 members (58,191 online)
Rate this:
Please Sign up or sign in to vote.
I have written a code for finding a transpose of a matrix as a separate program, it worked well.

But when Iam using that function into my main program, Iam getting wrong ans....

This was my code for function......

float trpse(int r,int c,float a[r][c],float atr[c][r])
{   int i,j;

I am using like this.....
float trpse(int,int,float[20][20],float[20][20]);
float A[20][20],At[20][20],yb[20][20],Ayb[20][20];
	printf("for A:\n");  /*Asking for input*/
            printf("%f ",At[i][j]);

For example:
My input is.....

for A:
1 2 3
4 5 6
Iam expecting to get this out of the function trpse:
1 4
2 5
3 6

But I am getting this.
1.000000 0.000000
0.000000 0.000000
0.000000 0.000000
Posted 14-Oct-12 4:59am
N Shiva531
Updated 14-Oct-12 5:41am
OriginalGriff 14-Oct-12 11:06am
What are you expecting to get, and what do you get?
Use the "Improve question" widget to edit your question and provide better information.
N Shiva 14-Oct-12 11:42am
See once.. I edited the question...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I think I know what the problem is, but without running it I can't be sure.
So, it's up to you to debug it!

Start like this (assuming you don't have a debugger - I don't know what flavour of C you are using)
Make a function that prints a two x two array.
Call it before you call trpse to check your input looks good.
Call it again after you call trpse to check what happens to your output.

If the input looks ok, and the output screwie, move the calls into trpse and check input as the first thing the function does, and output as the last.

Are they the same as the before and after outside the function. I'm betting not!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Replace your function to:

// forward declaration:
float trpse(int r,int c,float **a,float **atr);
// function definition:
float trpse(int r,int c,float **a,float **atr)
{   int i,j;

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,489
CHill60 3,330
Maciej Los 2,913
Jochen Arndt 1,935
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100