Grade 9 · 13 algorithmsCitește în română
Number sequences read one at a timeȘiruri de numere citite pe rând
Every number sequences read one at a time algorithm from the Romanian high school curriculum, with the idea explained, its complexity, examples and code you can edit and run right here.
- 13algorithms
- 8chapters
- 1grade
13 algorithms
0%
Number sequences read one at a time
Șiruri de numere citite pe rând · 13 algorithms
- Longest run of equal elementsCea mai lungă secvență de elemente egaleA run means elements on consecutive positions. lung is the length of the current run: it grows when the new number equals the previous one and goes…
- Largest Fibonacci term not greater than nCel mai mare termen Fibonacci cel mult egal cu nWe generate the terms of the Fibonacci sequence (1, 1, 2, 3, 5, ...) while the next term does not exceed n. The last term kept is the answer. We…
- The two largest valuesCele mai mari două valoriWe keep the largest value (max1) and the second one (max2). If the new number exceeds max1, the old max1 moves down to second place; otherwise, if…
- Reading a sequence terminated by 0Citirea unui șir terminat cu 0We do not know in advance how many numbers follow: we read up to the first 0, which only marks the end and is not part of the sequence. The program…
- GCD of several numbersCmmdc-ul mai multor numeregcd(a, b, c) = gcd(gcd(a, b), c). We keep in rez the GCD of the numbers read so far and combine it, with Euclid's algorithm, with every new number.…
- The n-th term of the Fibonacci sequenceAl n-lea termen al șirului lui FibonacciThe Fibonacci sequence starts with 1, 1 and every term is the sum of the two before it: 1, 1, 2, 3, 5, 8, ... We do not need an array: we keep only…
- Maximum and minimum of a sequenceMaximul și minimul unui șirn is read, then n integers. The maximum and the minimum start from the first number read (not from 0, because all numbers may be negative), then…
- Counting elements with a propertyNumărarea elementelor cu o proprietaten and n natural numbers are read. We count how many of them are even and how many have the last digit equal to the first. Each property has its own…
- Number of sign changesNumărul de schimbări de semnn non-zero numbers are read. A sign change happens between two consecutive terms with opposite signs, i.e. when their product is negative. We…
- Pairs of consecutive terms with a propertyPerechi de termeni consecutivi cu o proprietateWe count the pairs of adjacent terms that have the same parity. A sequence of n terms has n - 1 consecutive pairs; for every new term x, the pair is…
- Checking an arithmetic progressionVerificarea unei progresii aritmeticeA sequence is an arithmetic progression if the difference between two consecutive terms is always the same (the common difference). The difference…
- Checking a non-decreasing sequenceVerificarea unui șir crescătorThe sequence is non-decreasing if every number is at least equal to the one before it. We keep the previous number in the variable ant and compare…
- Sum and arithmetic meanSuma și media aritmeticăn and n integers are read; their sum and arithmetic mean are printed, with two decimals. For the mean we divide a real number by n (1.0 * suma / n);…