Guide · Basic examples
Basic Examples – a Guide to the Tasks
Here are practice tasks on programming basics, arranged in the order the material is learned: from data and operators, through branching and loops, to arrays, strings, functions, vectors and maps. Every page has tasks with an example of input and output, and many also have a hint or a solution.
The tasks are mostly in C and C++ (some in Java). They are meant for students from grade 5, especially those preparing for school and municipal informatics competitions.
- Grades 5–8 and secondary school
- C, C++, Java
- Tasks with solutions
- Competition preparation
Some lessons linked below are available only in Serbian for now. They are marked (SR).
1 First steps: data, operators, branching
Input and output, formulas, integer division and the remainder, and then decisions with if.
Data and arithmetic operators
11 tasks with solutions in C++: types, constants, formulas, overflow.
Open lesson →Operators (SR)
The digits of a number, converting time and angles, integer division.
Open lesson →Branching
if, else, switch: the maximum, a leap year, quadrants, horoscope.
Open lesson →2 Repetition: loops
Counters, sums, averages, reading until the end of input, and then a loop inside a loop.
3 More data: arrays, matrices, sorting
When data has to be remembered and processed several times.
4 Text and functions
Working with strings and splitting a program into smaller parts.
5 The C++ library: vectors and maps
Arrays of variable length and dictionaries (key → value).
6 After the basic examples
When you solve most of the tasks in this guide, continue with algorithms and competition tasks.
Guide: Algorithm examples
GCD, prime numbers, complexity, recursion, combinatorics, backtracking.
Open lesson →Additional examples with solutions
More tasks for practice and preparing for a test.
Open lesson →Combined tasks (SR)
Branching, loops and nested loops together.
Open lesson →Competitions
Tasks by competition level.
Open lesson →Suggested order
- Data and arithmetic operators
- Operators (SR)
- Branching
- Loops
- Nested loops
- Arrays
- Matrices
- Sorting
- Strings
- Functions
- Vectors and maps (SR)
Useful external resources
- Petlja – collections of tasks with automatic checking of solutions (in Serbian)
- Mathematical Society of Serbia – informatics – tasks and results of primary school competitions (in Serbian)
- OnlineGDB – running C/C++ programs in the browser, without installation
