|
Newbie
Join Date: Mar 2008
Posts: 3
Rep Power: 0 
|
I need help in writting pseudocode
Am really embarrasingly new to C/C++, a good thing you cant see me otherwise I wouldnt post here. Okay the thing is I got this book called C language by o relly, I didnt find it simple to understand. Our lecturer later gave us an assignment to code in C or C++ a program that multiplies two matrices m by n (no specific matrix size) and gives the output so I came up with this:
// program to multiply 2 matrices ( A and B or M by N of rows and columns defined by the user) # include <stdio.h> int main () { int d,i,j,k,l,m,n,p,q,t,u,x ; int A[m] [n]; int B[k] [l]; int C[t] [u]; i=0; d=0; j=0; j=0; k=0; l=0; m=0; n=0; n=0; p=0; q=0; t=0; u=0; x=0; /* Entre the size of the matrices A and B */ printf (" Entre no. of rows for 1st matrix : \n"); scanf (" %d", &m ); printf (" Entre no. of rows for 1st matrix : \n"); scanf (" %d", &m ); printf (" Entre no. of rows for 2nd matrix : \n"); scanf (" %d", &p ); printf (" Entre no. of columns for 2nd matrix : \n"); scanf (" %d", &q ); /* Entre the values of the matrices */ printf (" Entre values for 1st matrix from 1st row,1st col integer to the right end then 2nd row, 1st col to the right end.... : \n"); while ( i<m) { while ( j<n) { printf (" A[%d] [%d] = ? :" , i,j ); scanf ("%d", &A[i] [j] ); ++j; } j=0 ; ++i} printf (" Entre values for 2nd matrix from 1st row,1st col integer to the right end then 2nd row, 1st col to the right end.... : \n"); i=0;j=0 while (i<p) { while (j<q) { printf (" B[%d] [%d] = ? :" , i,j ); scanf ("%d", &B[i] [j] ); ++j; } j=0 ; ++i} i=0; j=0; /* Calculate the product of matrix A and matrix B */ while (k<p) { while ( i<m) { while (j<n) { C[t] [u]+=A[i] [j]*B[k] [l] ; ++j ; ++k ; } ++i ; ++t ; k=0 ; j=0 ; } t=0 ; ++u ; i=0 ; j=0 ; ++l ; k=0 ; } t=0; u=0; /* Read out the values of the obtained matrics C */ while (t<x) { while (u<d) { printf (" C[%d] [%d] = %d\t\t",t,u, C[t] [u]) ; } printf ("\n") ; ++u ; } u=0 ; ++t ; }
Like l said am new to this, so bear with me here. I wanted to know how to write its pseudocode, I developed a habbit of writting the code before the pseudocode. Now I need help in writting the pseudocode before the code. Am asking this because I failed in writting one. Can anyone help? If you dont mind I would appreciate I anyone can help me make it work.Its giving me an undefined A[m][n] error.
|