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

- Dec 10th 2008, 02: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. - Dec 10th 2008, 02:55 AMCaptainBlack
- Dec 13th 2008, 09: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, - Dec 13th 2008, 11:04 PMCaptainBlack
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