# Exercises

{% embed url="https://www.youtube.com/watch?v=G7KFxNh5Gew" %}

1. **Factorial Calculation:**&#x20;

Create two programs that calculates the factorial of a given integer. The first solution should have a while loop; the other solution should use a for loop

{% hint style="info" %}
The factorial function `(symbol: !)` says to multiply all whole numbers from our chosen number down to 1.

**Examples:**

* `4! = 4 × 3 × 2 × 1 = 24`&#x20;
* `7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040`&#x20;
* `1! = 1`
{% endhint %}

{% embed url="https://www.youtube.com/watch?v=bxmbYVKgNUI" %}

2. **Sum of Numbers:**&#x20;

Write a program that calculates the sum of all integers from 1 to N, where N is a user-entered positive integer.

{% embed url="https://www.youtube.com/watch?v=lVwQwc7nZc8" %}

3. **Longest Name:**

Create a program that takes an unknown amount of names and outputs the longest name. You will know that the inputs are done when the user has inputted a string of X.

{% tabs %}
{% tab title="Example" %}
```
Sample Input:
Kelsey
Tyree
X

Output:
Kelsey

```
{% endtab %}

{% tab title="Example 2" %}
```
Sample Input:
Lydia
Meredith
Garret
Erwin
Belinda
Prince
Dena
Tracy
Vera
Regina
X

Output:
Meredith

```
{% endtab %}
{% endtabs %}

{% embed url="https://www.youtube.com/watch?v=L0Xzodw0gGw" %}

4. **Prime Number Checker:**&#x20;

Create a program that checks whether a given number is prime or not.

{% hint style="info" %}
**Prime Numbers**

* 1 is not considered a prime number.
* A prime number is a number that is either 2 or greater.&#x20;
* A prime number only has two distinct factors, 1 and itself.

_Some examples:_ `2, 3, 5, 7, 11, 13`
{% endhint %}

{% embed url="https://www.youtube.com/watch?v=YOxqzHX7_88" %}

5. **Reverse a Number:**&#x20;

Write a program that reverses a given integer. For example, if the input is 12345, the program should output 54321.
