# Please write Psedocode

Printable View

• Dec 10th 2008, 02:35 AM
swikar.maths
Please write Psedocode
Write an algorithm that searches a sequence S, of length n, for the number of negative elements. The algorithm should return the number of negative elements.

i am appreciate for any potential answers from anybodies.
• Dec 10th 2008, 02:55 AM
CaptainBlack
Quote:

Originally Posted by swikar.maths
Write an algorithm that searches a sequence S, of length n, for the number of negative elements. The algorithm should return the number of negative elements.

i am appreciate for any potential answers from anybodies.

Initialise a counter to zero, then loop over the elements of the sequence incrementing the counter by one every time the element in the sequence is negative, return the counter.

CB
• Dec 13th 2008, 09:29 PM
swikar.maths
Write an algorithms return negative elements
Hello Captainblack,
you answered my question regarding Psedocode.
Please can you please writedown in Psedocode language like count = 0
for loop..

Please,
Thnaks,
• Dec 13th 2008, 11:04 PM
CaptainBlack
Quote:

Originally Posted by swikar.maths
Hello Captainblack,
you answered my question regarding Psedocode.
Please can you please writedown in Psedocode language like count = 0
for loop..

Please,
Thnaks,

There is no such thing as "Pseudo-Code", you make it up as you go, the key thing is that it can be translated unambiguously into a programming language. In which case:

Code:

`Initialize a counter to zero, then loop over the elements of the sequence incrementing the counter by one every time the element in the sequence is negative, return the counter.`
is pseudo-code, as is:

Code:

```Initialize a counter to zero, Loop over the elements of the sequence   Increment the counter by one every time the element is negative, return the counter.```
or:

Code:

```counter=0 for idx=1 to n   if S(idx)<0     counter=counter+1   endif endfor return counter```
CB