149k views
1 vote
Write a for loop that prints in ascending order all the positive multiples of 5 that are less than 175, separated by spaces?

User Nerielle
by
5.1k points

2 Answers

2 votes

Answer:

li = []

for i in range(5,175):

if i % 5 == 0:

li.append(i)

print(li)

Step-by-step explanation:

The above code was written in python 3 programming language.

Firstly, an empty list is created to hold the values that will be derived from the for loop.

for i in range(5,175):

The range module here generates a list from 5 to 174, The for loop iterates through each number and checks if they are in agreement with the IF statement. i.e. If they are divisible by five and leave no remainder and then appends(adds) the values to the empty list and the loop runs again till it gets to 174, and then it stops.

I have attached a picture for you to see the result and how the code runs.

Write a for loop that prints in ascending order all the positive multiples of 5 that-example-1
User Shadia
by
6.0k points
4 votes

Answer:

The answer to the following question by the C++ programming language.

#include <iostream> //header file

using namespace std; // namespaces

int main() // main function

{

for (int i=1; i<175; i++){ // set for loop

if ((i % 5) == 0){ // set if condition

cout << i << " ";

}

}

}

Output:

5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 13 0 135 140 145 150 155 160 165 170

Step-by-step explanation:

Here, we define header file and namespaces.

Then, we define the main() function.

Then, we set the for loop, which starts from 1 and stop at 174.

Then, we set the if condition, which divides each integer value from 1 to 174 from 5.

Then we set "cout<< ;" which prints all those integer values which is divided by 5 with space.

User Elias Fyksen
by
6.0k points