You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Content/Chapter-7-1-complex-loops/loop-step/loop-step.md
-58
Original file line number
Diff line number
Diff line change
@@ -32,61 +32,3 @@ We can solve the problem using the following sequence of actions \(algorithm\):
32
32
33
33
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/514\#0](https://judge.softuni.org/Contests/Practice/Index/514#0).
34
34
35
-
## Example: Numbers N...1 in Reverse Order
36
-
37
-
Write a program that prints the numbers from **n to 1 in reverse order**\(step of -1\). For example, **if n = 100**, the result will be: **100, 99, 98, …, 3, 2, 1**.
38
-
39
-
We can solve the problem in the following way:
40
-
41
-
* We read the number `n` from the console input.
42
-
* We create a `for`** loop** by assigning `int i = n`.
43
-
* We reverse the condition of the loop: `i >= 1`.
44
-
* We define the size of the step: **-1**.
45
-
* In **the body of the loop**, we print the value of the current step.
Watch this video lesson to learn how to print the numbers from N down to 1 \(in reverse order\) using a for loop: [https://youtu.be/LGPZ-ug3qh0](https://youtu.be/LGPZ-ug3qh0).
52
-
53
-
### Testing in the Judge System
54
-
55
-
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/514\#1](https://judge.softuni.org/Contests/Practice/Index/514#1).
56
-
57
-
## Example: Numbers from 1 to 2^n with a For Loop
58
-
59
-
In the following example, we will look at using the usual step with size of 1, combined with a calculation at each loop iteration.
60
-
61
-
Write a program that prints the numbers from **1 to 2^n**\(two in power of n\). For example, **if n = 10**, the result will be: **1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024**.
Watch this video lesson to learn how to iterate over the number from 1 to 2^n using a for-loop: [https://youtu.be/B2k\_yx3EV0I](https://youtu.be/B2k_yx3EV0I).
68
-
69
-
### Testing in the Judge System
70
-
71
-
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/514\#2](https://judge.softuni.org/Contests/Practice/Index/514#2).
72
-
73
-
## Example: Even Powers of 2
74
-
75
-
Print **the even** powers of **2** to **2^n**: **2^0, 2^2, 2^4, 2^8, …, 2^n**. For example, if **n = 10**, the result will be: **1, 4, 16, 64, 256, 1024**.
76
-
77
-
Here is how we can solve the problem:
78
-
79
-
* We create a `num` variable for the current number to which we assign an initial **value of 1**.
80
-
* For **a step** of the loop, we set a value of **2**.
81
-
* In **the body of the loop**: we print the value of the current number and **increase the current number **`num`** 4 times**\(according to the problem's description\).
82
-
83
-

84
-
85
-
### Video: Even Powers of 2
86
-
87
-
Watch this lesson to learn how to print the even powers of 2 using a for loop: https://youtu.be/H8t4HGn\_Ap4.
88
-
89
-
### Testing in the Judge System
90
-
91
-
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/514\#3](https://judge.softuni.org/Contests/Practice/Index/514#3).
Print **the even** powers of **2** to **2^n**: **2^0, 2^2, 2^4, 2^8, …, 2^n**. For example, if **n = 10**, the result will be: **1, 4, 16, 64, 256, 1024**.
4
+
5
+
## Video: Even Powers of 2
6
+
7
+
Watch this lesson to learn how to print the even powers of 2 using a for loop: [https://youtu.be/H8t4HGn\_Ap4](https://youtu.be/H8t4HGn_Ap4).
8
+
9
+
## Hints and Guidelines
10
+
11
+
Here is how we can solve the problem using a **for-loop with a step**:
12
+
13
+
* We create a `num` variable for the current number to which we assign an initial **value of 1**.
14
+
* For **a step** of the loop, we set a value of **2**.
15
+
* In **the body of the loop**: we print the value of the current number and **increase the current number **`num`** 4 times**\(according to the problem's description\).
16
+
17
+

18
+
19
+
## Testing in the Judge System
20
+
21
+
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/514\#3](https://judge.softuni.org/Contests/Practice/Index/514#3).
In the following example, we will look at using the usual step with size of 1, combined with a calculation at each loop iteration.
4
+
5
+
Write a program that prints the numbers from **1 to 2^n**\(two in power of n\). For example, **if n = 10**, the result will be: **1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024**.
6
+
7
+
## Video: Numbers 1 ... 2^n
8
+
9
+
Watch this video lesson to learn how to iterate over the number from 1 to 2^n using a for-loop: [https://youtu.be/B2k\_yx3EV0I](https://youtu.be/B2k_yx3EV0I).
10
+
11
+
## Hints and Guidelines
12
+
13
+
The code below demonstrates how we can **calculate the powers of 2** for given **n** using a for-loop with a calculation at the end of its body:
Write a program that prints the numbers from **n to 1 in reverse order**\(step of -1\). For example, **if n = 100**, the result will be: **100, 99, 98, …, 3, 2, 1**.
4
+
5
+
## Video: Numbers N...1
6
+
7
+
Watch this video lesson to learn how to print the numbers from N down to 1 \(in reverse order\) using a for loop: [https://youtu.be/LGPZ-ug3qh0](https://youtu.be/LGPZ-ug3qh0).
8
+
9
+
## Hints and Guidelines
10
+
11
+
We can solve the problem in the following way:
12
+
13
+
* We read the number `n` from the console input.
14
+
* We create a `for`** loop** by assigning `int i = n`.
15
+
* We reverse the condition of the loop: `i >= 1`.
16
+
* We define the size of the step: **-1**.
17
+
* In **the body of the loop**, we print the value of the current step.
0 commit comments