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

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:

- Accept the given number as ‘n’
- Initialize a number ‘i’ with value 1
- 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)
- 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...

Tagged in

Find answers to questions asked by student like you

Show more Q&A

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...

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...

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...

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

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

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:

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...

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 ...

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...

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 “...