PDA

View Full Version : Modular progams (pseudo-code algorithm)


nova2177
Jul 12, 2008, 03:48 PM
how do you extract a module from a pseudo-code algorithm.
I'm not sure if I can post the question here but here goes.

a) write an algorithm that will display the sum for a given numbers of squares, e.g. if the user enter the value 3, then the output should be 1² + 2² + 3² = 14
b) from (a) use a module called sumsquare that will accept an integer value and return the sum of the squares of the value entered
c) use the sumsquare module to write an algorithm that will perform the same function as (a)

I think I figured out (a) but I have never done modules, I only know what it is. If some one can help me out, please help, show me an example of some sort, doesn't have to be the question that I post.
thanks.

KISS
Jul 12, 2008, 04:48 PM
This is how I interpret the question.

a) Is just plain pseudocode

b) Basically means something that will use "include sumsquare.c"
In sumsquare.c is a function sumsquare[x].

c) in pseudocode
main.c
input x
print sumsquare (x)
end main

sumsquare.c
function sumsquare(x)
return sum of squares (x)
end sumsquare.c

My c is very rusty.

Basically your creating two programs of source code.

Does this make sense?