Skip to content

Commit 4a7c0f9

Browse files
committed
Chapter 7.1 - Grammarly + Upper Letter Titles
1 parent aa0a6b3 commit 4a7c0f9

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

chapter-07-complex-loops.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In the current chapter, we will also take a look at the **`break`** operator and
1111

1212
## Loops with a Step
1313

14-
In the **"Loops (Repetitions)"** chapter we learned how the **`for`** loop works and we already know when and to what purpose to use it. In the present chapter we will **take a look** at a particular and a very important **part of this structure** - its **step** or as it is also known **step**.
14+
In the **"Loops (Repetitions)"** chapter we learned how the **`for`** loop works and we already know when and to what purpose to use it. In the present chapter we will **take a look** at a particular and a very important **part of this structure** - its **step**.
1515

1616
### Loop with a Step – Explanation
1717

@@ -23,7 +23,7 @@ Most often we have a **size of `1`** and in this case, instead of writing **`i +
2323

2424
Here is a series of sample problems, the solution of which will help us better understand the use of a **step** in a **`for`** loop.
2525

26-
### Problem: Numbers from 1 to N with a step of 3
26+
### Problem: Numbers 1...N with Step 3
2727

2828
Write a program that prints the numbers **from 1 to n** with a **step of 3**. For example, **if n = 100**, then the output would be: **1, 4, 7, 10, …, 94, 97, 100**.
2929

@@ -39,7 +39,7 @@ We can solve the problem using the following sequence of actions (algorithm):
3939

4040
You can test your solution at the following link: [https://judge.softuni.org/Contests/Practice/Index/937#0](https://judge.softuni.org/Contests/Practice/Index/937#0).
4141

42-
### Problem: Numbers from N to 1 in Reverse
42+
### Problem: Numbers N...1
4343

4444
Write a program that prints the numbers **from n to 1 in reverse** (step -1). For example, **if n = 100**, then the output will be: **100, 99, 98, …, 3, 2, 1**.
4545

@@ -57,7 +57,7 @@ We can solve the problem in the following manner:
5757

5858
You can test your solution at the following link: [https://judge.softuni.org/Contests/Practice/Index/937#1](https://judge.softuni.org/Contests/Practice/Index/937#1).
5959

60-
### Problem: Numbers from 1 to 2^n with a For Loop
60+
### Problem: Powers of Two
6161

6262
In the following example, we will use the standard size 1 step.
6363

@@ -86,9 +86,9 @@ Here is how we can solve the problem:
8686

8787
You can test your solution at the following link: [https://judge.softuni.org/Contests/Practice/Index/937#3](https://judge.softuni.org/Contests/Practice/Index/937#3).
8888

89-
## While loop
89+
## While Loop
9090

91-
The next type of loops that we will familiarize, which are called **`while` loops**. The special thing about them is that they repeat a command block **while a condition is met**. Their structure is a bit different than that of the **`for`** loops, however, they boast a simpler syntax.
91+
The next type of loops that we will familiarize are called **`while` loops**. The special thing about them is that they repeat a command block **while a condition is met**. Their structure is a bit different than that of the **`for`** loops, however, they boast a simpler syntax.
9292

9393

9494
### While Loop – Explanation
@@ -100,7 +100,7 @@ In programming, the **`while` loop** is used when we want to **repeat** the exec
100100
Here is a series of sample problems, the solutions of which will help us better understand the use of the **`while`** loop.
101101

102102

103-
### Problem: Sequence of Numbers 2k+1
103+
### Problem: Sequence 2k+1
104104

105105
Write a program that prints **all numbers ≤ n** in the series: **1, 3, 7, 15, 31, …**, assuming that each number is generated according to the following formula nextNumber = **previousNumber \* 2 + 1**.
106106

@@ -119,7 +119,7 @@ Here is a sample implementation of this idea:
119119

120120
You can test your solution here: [https://judge.softuni.org/Contests/Practice/Index/937#4](https://judge.softuni.org/Contests/Practice/Index/937#1).
121121

122-
### Problem: Number in Range [1100]
122+
### Problem: Number in Range [1...100]
123123

124124
Enter an integer in the range [**1 … 100**]. If the entered number is **invalid**, enter **another**. In this case, an invalid number would be any number that is **outside** the given range.
125125

@@ -195,7 +195,7 @@ We will solve the problem by implementing **Euclid's algorithm**:
195195

196196
You can test your solution here: [https://judge.softuni.org/Contests/Practice/Index/937#6](https://judge.softuni.org/Contests/Practice/Index/937#6).
197197

198-
## Do-while loop
198+
## Do-While Loop
199199

200200
The next type of loop we will study is the **`do-while`** loop. By structure it resembles the **`while`**, but with a significant difference. The **`do-while`** will execute its body **at least once**. Why is this? In the **`do-while`** loop structure, the **condition** is always checked **after** the body, which ensures that the **first loop iteration** will **execute** the code and the check for **the end of the loop** will be applied to each **subsequent** iteration of the **`do-while`**.
201201

@@ -204,7 +204,7 @@ The next type of loop we will study is the **`do-while`** loop. By structure it
204204
Now we should proceed with the usual set of practical problems, that will help us better understand the **`do-while`** loop.
205205

206206

207-
### Problem: Calculating Factorial
207+
### Problem: Factorial
208208

209209
For natural **n** number, calculate **n! = 1 \* 2 \* 3 \*\* n**. For example, if **n = 5**, then the result would be: **5!** = 1 \* 2 \* 3 \* 4 \* 5 = **120**.
210210

@@ -224,7 +224,7 @@ Here is how we can calculate factorial in more detail:
224224

225225
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/937#7](https://judge.softuni.org/Contests/Practice/Index/937#7).
226226

227-
### Problem: Summing the Digits of a Number
227+
### Problem: Sum Digits
228228

229229
Sum up the digits of the integer **positive** number **n**. For example if **n = 5634**, then the output would be: 5 + 6 + 3 + 4 = **18**.
230230

@@ -274,7 +274,7 @@ We already know that the infinite loop executes a certain code infinitely, but w
274274
<td>The operator <b><code>break</code></b> stops a loop's execution at the point it is called and the execution continues from the first line after the end of the loop. This means that the current iteration of the loop will not be completed accordingly and the rest of the code in the body of the loop will not be executed.</td>
275275
</tr></table>
276276

277-
### Problem: Prime Number Checking
277+
### Problem: Check Prime
278278

279279
The next problem we are going to solve is to **check whether a given number is prime**, but before that, we should remember what are prime numbers.
280280

@@ -299,14 +299,14 @@ Here are some examples of composite numbers:
299299
<td>We can optimize the algorithm by instead of checking until <code><strong>n-1</strong></code>, checking divisors only until <code><strong>√n</strong></code>. Think of the reasons why this is so.</td>
300300
</tr></table>
301301

302-
### Problem: Check for a Prime Number. Break Operator
302+
### Problem: Enter Even Number
303303

304304
You are tasked to write a function that takes a single input **n** integer and checks if it is prime. This can be implemented by checking if **n** is divisible by any numbers in the range between 2 and √n.
305305

306306
The steps of the **"prime checking algorithm"** are given below in bigger detail:
307307

308308
* We declare the variable **`n`**, to which we assign the integer passed to our function.
309-
* We create a **`prime`** boolean with and an initial value of **`true`**. We assume that a number is prime until proven otherwise.
309+
* We create a **`prime`** boolean with, and an initial value of **`true`**. We assume that a number is prime until proven otherwise.
310310
* We create a **`for`** loop, with the initial value set to 2, for a condition the **current value `<= √n`**. The step is set to 1.
311311
* In the **body of the loop**, we check if **`n`**, divided by the **current value** has a remainder. If there is **no reminder** from the division, then we change **`prime`** to **`false`** and exit the loop through the **`break`** operator.
312312
* Depending on the value of **`prime`** we print whether the input number is prime (**`true`**) or composite (**`false`**).
@@ -315,13 +315,13 @@ Here is a sample implementation of the prime checking algorithm, described above
315315

316316
![](assets/chapter-7-1-images/10.Check-if-prime-01.png)
317317

318-
What remains is to add a **condition that checks if the input number is greater than 1**, because, by definition numbers such as 0, 1, -1 and -2 are not prime.
318+
What remains is to add a **condition that checks if the input number is greater than 1**, because, by definition numbers such as 0, 1, -1, and -2 are not prime.
319319

320320
#### Testing in The Judge System
321321

322322
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/937#9](https://judge.softuni.org/Contests/Practice/Index/937#9).
323323

324-
### Problem: The break Operator in an Infinite Loop
324+
### Problem: Break Sum
325325

326326
Write a function, which checks whether a given number **n** is even and if so - print it on the console. An even number can be divided by 2 without a remainder. If the number is invalid, we will print that the current number is not even and the user will need to input a new number.
327327

@@ -380,7 +380,7 @@ Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/937#
380380

381381
In this chapter, we got familiar with a few new types of loops that can perform repetitions with more complex programming logic. Let's solve a few practical problems using these new constructs.
382382

383-
### Problem: Fibonacci Numbers
383+
### Problem: Fibonacci
384384

385385
Fibonacci's numbers in mathematics form a sequence that looks like this: **1, 1, 2, 3, 5, 8, 13, 21, 34, …**.
386386

@@ -425,7 +425,7 @@ Example implementation:
425425

426426
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/937#12](https://judge.softuni.org/Contests/Practice/Index/937#12).
427427

428-
### Problem: Numbers Pyramid
428+
### Problem: Number Pyramid
429429

430430
Print the **numbers 1 … n in a pyramid** as per the below example. On the first row, we print one number, at the second we print two, at the third, we print three, and so on, until the numbers are over. On the last line, we print as many numbers as we get until we get to **n**.
431431

@@ -437,7 +437,7 @@ Print the **numbers 1 … n in a pyramid** as per the below example. On the firs
437437

438438
#### Hints and Guidelines
439439

440-
We can solve the problem with **two nested loops** (by rows and columns) with printing in them and leaving when the last number is reached. Here is the idea, written in more detail:
440+
We can solve the problem with **two nested loops** (by rows and columns) by printing in them and leaving when the last number is reached. Here is the idea, written in more detail:
441441

442442
* We declare a variable **`n`**, to which we assign the integer value passed to our function.
443443
* We declare a variable **`num`** with an initial value of **1**. It will hold the count of printed numbers. At each iteration, we will **increment** it by **1** and will add it to the current row.
@@ -460,7 +460,7 @@ Here is an example implementation:
460460
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/937#13](https://judge.softuni.org/Contests/Practice/Index/937#13).
461461

462462

463-
### Problem: Numbers Table
463+
### Problem: Number Table
464464

465465
Print the numbers 1 … n in a table as per the examples below:
466466

0 commit comments

Comments
 (0)