# Introductory Exercises

Jump to navigationJump to search

# Introductory Exercises

This is a small list of exercises for beginners. Some of them require minimal math knowledge. I will try and make references to that knowledge, when possible.

## Problems with numbers (no sequences as input)

### First Degree Equation i

Solve the first degree equation with one variable: `ax + b = 0`, given `a` and `b` as input.

### Second Degree Equation i

Solve the second degree equation with one variable: `ax2 + bx + c = 0`, given `a, b` and `c` as input.

### Divisibility Test i

Find out if `n` is divisible by `k`.

### Leap Year Test i

Find out if year `y` is a leap year.

### kth digit

Extract the kth digit of a number, counting digits from right to left

### Triangle Edges i

Can three input numbers be the lengths of the three edges of a triangle?

### Swap Variables i

Given variables `a` and `b` exchange their values so that in the end `a` will contain the old value of `b` and `b` will contain the old value of `a`.

### Swap Variables Restricted i h

Given variables `a` and `b` exchange their values so that in the end `a` will contain the old value of `b` and `b` will contain the old value of `a`, without using any other variables.

### Divisors

Display all of number `n`'s divisors.

### Primality

Is number `n` a prime number?

### Reverse Digits

Display in reverse order the digits of a number `n`

### Multiple Count i h

How many integers divisible by `n` lie in interval `[a, b]`?

### Leap Year Count i h

How many years between `y1` and `y2` are leap years?

### Palindrome h

Is number `n` a [palindrome]? A palindrome is a symmetrical number, like 15351 or 12233221.

### Sort numbers i

Display three input integers in ascending order.

### Sort more numbers i h

Display five input integers in ascending order. Make the flow chart fit on one letter page.

### GCD and LCM

Find the [greates common divisor] and the [lowest common multiple] of two numbers. Use [Euclid's algorithm]. Example: GCD of 24 and 32 is 8.

### Prime Factors

Display the [prime factor decomposition] of input number `n`. Example: 1176 = 23 x 31 x 72

### Numbers with two digits

Is number `n` formed with exactly 2 digits repeated any number of times? 23223 and 900990 are such numbers, while 593 and 44002 are not.

### Decimal Fraction h

Display fraction `m/n` in decimal format, with the period between brackets. Example: 13/30 = 0.4(3)

### Number Guessing

Guess a number between 1 and 1024 by asking questions of the form "is the number greater or equal to x".

Legend:

• i means that the problem can be solved without loops, using only if-then-else structures.
• h means hard. The problem is difficult.