Question
Asked Feb 18, 2019
3 views

how to write a function that takes an integer n and prints all of the integers between 1 and n which are multiple of 5 using while loop

check_circle

Expert Answer

Step 1

Since no programming language is specified we choose python as it is one of most popular programming language in various domains. However, the algorithm will remain same irrespective of the programming language.

Algorithm:

  1. Accept the given number as ‘n’
  2. Initialize a number ‘i’ with value 1
  3. Run a while loop checking the condition that the value of ‘i’ is <= n (enter the body of the while loop only if this condition is true)
  4. Inside the while loop check if the value of ‘i’ modulo 5 is equal to zero, if yes then print the number ‘i’ else do nothing. Also increment the value of ‘i’ by I inside the while loop.
Step 2

The python program (a functio...

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Algorithms

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: What language is accepted by the npda M = ({q0, q1, q2}, {a, b}, {a, b, z}} q0, z, {q2}). δ(q0,a,z)=...

A: The given npda is M = ({q0, q1, q2}, {a, b}, {a, b, z}} q0, z, {q2}) with transition functions asδ(q...

question_answer

Q: Try giving these 2 commands $ echo cat$ cat echoExplain the differences between the output of each c...

A: echo command:echo command is used to display the line of text passed as an argument. It is a built i...

question_answer

Q: Transform the grammar S → aSaaA|A, A → abA|bb into Chomsky normal form.

A:  For solving your problem , first of all we will discuss about  algorithm to convert grammar into  C...

question_answer

Q: Show that the following grammar is ambiguous: S → aSbS |bSaS| λ.

A: Solution:Given that,Proof: Given grammar is ambiguous.

question_answer

Q: 1.6 Compute the scalar cardinality and the fuzzy cardinality for each of thefollowing fuzzy set.

A: The scalar cardinality of a fuzzy set is calculated using the formula:

question_answer

Q: Visual Basic. Given two variables, isEmpty of type boolean, indicating whether a class roster is emp...

A: We will have two check the below conditions:-1) class roster is not empty2) the class is one or thre...

question_answer

Q: The speed of computers has increased greatly over the history of computing. The traveling salesman p...

A: TSP is an NH Hard problem, if solved by brute force method it takes (n-1)! time where n is the size ...

question_answer

Q: Create a new file in C++ and save it as lab12_XYZ.cpp  Consider rolling two six-sided dice. Whil...

A: Program Instructions:Declare the header files, constants, and prototypes.In main() call functions di...

question_answer

Q: Construct npda that accept the following languages on Σ = {a, b, c}: L = {wcwR : w ∈ {a, b}∗}.

A: Non-deterministic pushdown automaton (NPDA):Given: L = {wcwR : w ∈ {a, b}∗}To construct NPDA, when “...