• :00Days
  • :00Hours
  • :00Mins
  • 00Seconds
A new era for learning is coming soonSign up for free
Log In Start studying!

Select your language

Suggested languages for you:
Answers without the blur. Sign up and see all textbooks for free! Illustration

Q6E

Expert-verified
Discrete Mathematics and its Applications
Found in: Page 202
Discrete Mathematics and its Applications

Discrete Mathematics and its Applications

Book edition 7th
Author(s) Kenneth H. Rosen
Pages 808 pages
ISBN 9780073383095

Answers without the blur.

Just sign up for free and you're in.

Illustration

Short Answer

Describe an algorithm that takes an input a list of integers and finds the number of negative integers in the list.

The algorithm that takes as input a list of integers for finding number of negative integers is as follows:

procedure countneg ( a1,a2, ....., an : integers with n 1)K : = 0for i =1 to n if ai<1 then k : K +1return k

See the step by step solution

Step by Step Solution

Step 1: Describing the steps needed to write the required algorithm:

We can call the algorithm as ‘countneg’ and input is a list of n integers

procedure countneg ( a1,a2, ....., an : integers with n 1)

We initially define the variable k as 0 ( k will count the negative numbers).

K : = 0

For every integer between 1 and n , ai is negative, then we increase the variable by 1.

for i =2 to n if ai<1 then k : K +1

Finally, we return the k which counts the negative numbers in the set

return k

Step 2: Combining all the steps to form an algorithm:

The algorithm is as follows:

procedure countneg ( a1,a2, ....., an : integers with n 1)K : = 0for i =1 to n if ai<1 then k : K +1return k

Therefore, the required algorithm is designed for the given conditions.

Recommended explanations on Math Textbooks

94% of StudySmarter users get better grades.

Sign up for free
94% of StudySmarter users get better grades.