Skip to content

Commit 7b73e34

Browse files
author
Svetlin Nakov
committed
Updates Content/Chapter-7-1-complex-loops/loop-step/loop-step/example-even-powers-of-2.md
Auto commit by GitBook Editor
1 parent f04a65e commit 7b73e34

File tree

5 files changed

+69
-58
lines changed

5 files changed

+69
-58
lines changed

Content/Chapter-7-1-complex-loops/loop-step/loop-step.md

-58
Original file line numberDiff line numberDiff line change
@@ -32,61 +32,3 @@ We can solve the problem using the following sequence of actions \(algorithm\):
3232

3333
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/514\#0](https://judge.softuni.org/Contests/Practice/Index/514#0).
3434

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.
46-
47-
![](/assets/chapter-7-images/02.Numbers-n-to-1-01.png)
48-
49-
### Video: Numbers N...1
50-
51-
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**.
62-
63-
![](/assets/chapter-7-images/03.Numbers-1-to-2^n-01.png)
64-
65-
### Video: Numbers 1 ... 2^n
66-
67-
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-
![](/assets/chapter-7-images/04.Even^2-01.png)
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).
92-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Example: Even Powers of 2
2+
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+
![](/assets/chapter-7-images/04.Even^2-01.png)
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).
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Example: Numbers from 1 to 2^n with a For Loop
2+
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:
14+
15+
![](/assets/chapter-7-images/03.Numbers-1-to-2^n-01.png)
16+
17+
## Testing in the Judge System
18+
19+
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/514\#2](https://judge.softuni.org/Contests/Practice/Index/514#2).
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Example: Numbers N...1 in Reverse Order
2+
3+
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.
18+
19+
![](/assets/chapter-7-images/02.Numbers-n-to-1-01.png)
20+
21+
## Testing in the Judge System
22+
23+
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/514\#1](https://judge.softuni.org/Contests/Practice/Index/514#1).
24+

SUMMARY.md

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
* [Problem: Axe](Content/Chapter-6-2-nested-loops-exam-problems/exam-problems/axe/axe.md)
162162
* [7.1. More Complex Loops](Content/Chapter-7-1-complex-loops/overview.md)
163163
* [For Loop with Step](Content/Chapter-7-1-complex-loops/loop-step/loop-step.md)
164+
* [Example: Numbers N...1](Content/Chapter-7-1-complex-loops/loop-step/loop-step/example-numbers-n1.md)
165+
* [Example: Numbers 1...2^n](Content/Chapter-7-1-complex-loops/loop-step/loop-step/example-numbers-12n.md)
166+
* [Example: Even Powers of 2](Content/Chapter-7-1-complex-loops/loop-step/loop-step/example-even-powers-of-2.md)
164167
* [While Loop](Content/Chapter-7-1-complex-loops/while-loop/while-loop.md)
165168
* [Greatest Common Divisor](Content/Chapter-7-1-complex-loops/greatest-common-divisor/greatest-common-divisor.md)
166169
* [Do-while Loop](Content/Chapter-7-1-complex-loops/do-while-loop/do-while-loop.md)

0 commit comments

Comments
 (0)