![]() |
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:
:
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. |
Re: I need help in writting pseudocode
The biggest problem is this part here:
:
int A[m] [n];There are two problems with this:
I'd recommend putting an upper-boundary on how large the matrix can be. Then simply make the array that large. :
#define MAX 100Look up "for loops" in your book, or online. All of your while loops should be replaced by for loops. It would make this much easier for you. Psuedocode won't help much in this instance, since you seem to have the general idea down. You just don't yet know how to code, right? |
Re: I need help in writting pseudocode
Quote:
For example the following code is valid: :
Of course VLA operands will cause problems when compiled with C++. As you mentioned you could use C or C++, you may want to consider moving to a compiler that will support C99. of course you must also make sure that the expression you are using to specify the size of the array is defined first ;). |
Re: I need help in writting pseudocode
Yes, but until C99 is standard (not to mention completely compliant *points at GCC*) across all compilers, let's try not to confuse the original poster, or rely on specific features when more reliable alternatives exist?
|
Re: I need help in writting pseudocode
I agree with Sane here, but C99 is pretty neat. How long has it been? 9 years? GCC should really get on adding missing support (especially the complex numbers and tgmath.h).
EDIT: A lot is actually missing. http://gcc.gnu.org/gcc-4.3/c99status.html |
Re: I need help in writting pseudocode
@Sane "I'd recommend putting an upper-boundary on how large the matrix can be"
int A[m] [n]; int B[k] [l]; int C[t] [u]; Giving an upper boundary on how large would fail the question because the question asked of m by n size (no boundaries) actually these are meant to be arrays defined during the running of the program not before the program begins. Am sure am missing some kind of library reference or some kind of inclusion so that it may actually be arrays whose size is determined by the user ** Guys I made a mistake I should have posted this in C language not C++. Can this be transfered to the C section? ** Am using visual c++ 6.0 to code in c language |
Re: I need help in writting pseudocode
Moved :)
|
Re: I need help in writting pseudocode
Quote:
Think of it this way: your computer does not have enough memory to handle a 1,000,000 x 1,000,000 matrix. Thus, the user can not enter 1,000,000. Therefore, there is an obvious restriction on the size. This restriction is your upper-boundary, and in the event that the user enters a very large number, it will have to be enforced one way or another in order to prevent the program from crashing. My suggestion of creating an upper-boundary, always making the array that large, and then only using the values within the inputted sizes-- is the easiest way to handle everything in one fell swoop. Quote:
|
Re: I need help in writting pseudocode
Quote:
Quote:
|
Re: I need help in writting pseudocode
Writing pseudocode is worth a couple chapters of its own... I have a programming logic book I'll sell you cheap. Simple Program Design : A step-by-Step Approach Fifth Edition.
Its usualy a prerequisite to any actual programming class. |
| All times are GMT -5. The time now is 4:18 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC