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.

Printable View

- December 10th 2008, 03:35 AMswikar.mathsPlease 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. - December 10th 2008, 03:55 AMCaptainBlack
- December 13th 2008, 10:29 PMswikar.mathsWrite 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, - December 14th 2008, 12:04 AMCaptainBlack
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.`

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.

Code:`counter=0`

for idx=1 to n

if S(idx)<0

counter=counter+1

endif

endfor

return counter