1
$\begingroup$

So here's the code:-

DECLARE number as INTEGER

PRINT "Enter a number"

INPUT number

DECLARE randomarray [1:number] AS INTEGER

Is this possible? i.e whilst declaring arrays, can we use variables?

Note:The question is strictly limited to pseudocode or general programming language

$\endgroup$
  • 4
    $\begingroup$ Pseudocode is not a formally defined language. You can do anything, as long as it's clear what it means. $\endgroup$ – David Richerby May 11 '18 at 13:50
  • $\begingroup$ Do you think this is good then? $\endgroup$ – Shashwat Tomar May 11 '18 at 13:52
  • $\begingroup$ It seems entirely clear to me. $\endgroup$ – David Richerby May 11 '18 at 13:57
1
$\begingroup$

Pseudocode is not a formally defined programming language. Rather, it refers to textual description of code that is not in "paragraph" form but rather in "code" form. (Paraphrasing Molière, it is a third form of expression, after prose and poetry.)

The only rule in pseudocode is that it should be self-explanatory. If there is anything that the reader might misunderstand, you have to explain it. Otherwise, it's up to you how you write pseudocode, though it's good measure to be consistent in your paper.

Your pseudocode is self-explanatory. You have declared a variable "number" of type integer, printer "Enter a number", read a number from the input into "number", and then declared an integer array "randomarray" of length "number". Moreover, your array is "1-based" (i.e., the first index is 1). If this is what you intended to convey, then you were successful and there is nothing wrong with your pseudocode.

It's good practice to try to emulate the way other people in your field write pseudocode. This will cause your code to look more "standard", and so more "professional" and easier to read. But it's definitely not necessary, and you are encouraged to write the pseudocode in whatever way seems best or nicest to you.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.