221k views
3 votes
Assume there are two variables, k and m, each already associated with a positive integer value and further assume that k's value is smaller than m's. Write the code necessary to compute the number of perfect squares between k and m. (A perfect square is an integer like 9, 16, 25, 36 that is equal to the square of another integer (in this case 3*3, 4*4, 5*5, 6*6 respectively).) Associate the number you compute with the variable q. For example, if k and m had the values 10 and 40 respectively, you would assign 3 to q because between 10 and 40 there are these perfect squares: 16, 25, and 36,.

1 Answer

4 votes

Answer:

The correct answer of the given question is:

The following code is written in python.

i = 1

q = 0

while i * i < k :

i += 1

while i * i <= m :

q += 1

i += 1

Step-by-step explanation:

Firstly we have two variables which is "k" and the second one is "m" and they have a positive integer value

If we discuss about to our code then, we take a variable "i" and value assign to it is "1" and then we take another variable "q" and value assign to it is "0", as per the question we check the condition of the variable "k" and then "m".

User Korrekorre
by
5.3k points