Grade 10 · 11 algorithmsCitește în română
Subprograms (functions)Subprograme (funcții)
Every subprograms (functions) algorithm from the Romanian high school curriculum, with the idea explained, its complexity, examples and code you can edit and run right here.
- 11algorithms
- 6chapters
- 1grade
11 algorithms
0%
Subprograms (functions)
Subprograme (funcții) · 11 algorithms
- GCD and LCM functionsFuncție cmmdc și cmmmcThe function cmmdc(a, b) applies Euclid's algorithm by division: while b is not 0, the pair (a, b) becomes (b, a % b). The function cmmmc(a, b)…
- Primality functionFuncție de primalitateWe write the function estePrim(x) once, returning true if x is prime, and call it for every number read. The function looks for a divisor d between…
- Function with an array parameter (the maximum)Funcție cu vector ca parametru (maximul)An array is passed to a function together with the number of elements: int maxim(int v[], int n). The function actually receives the address of the…
- Function returning the reverse of a numberFuncție care întoarce oglinditulThe function oglindit(x) builds the number with the digits of x in reverse order and returns it. With its help, the function palindrom(x) fits on…
- Function for the sum of digitsFuncție pentru suma cifrelorThe function sumaCifre(x) receives the number by value (it works on a copy, so the x in main is not destroyed) and returns the sum of its digits. In…
- Swapping by referenceInterschimbare prin referințăWe compare two functions that try to swap the values of two variables. schimbaValoare(int x, int y) receives copies, so the changes are lost when…
- Minimum and maximum returned by referenceMinim și maxim întoarse prin referințăA function can return a single value with return. When we need several results, we make them reference parameters: void minMax(int v[], int n, int…
- Amicable numbersNumere prieteneTwo numbers a and b are amicable if the sum of the proper divisors of a (the divisors smaller than a) is b and the sum of the proper divisors of b…
- Super-prime numbersNumere superprimeA number is super-prime if all its prefixes are prime. For example 239 is super-prime: 2, 23 and 239 are prime. The function estePrim(x) is reused…
- Palindromes in a rangePalindroame dintr-un intervalA problem solved by splitting it into small functions: oglindit(x) returns the reverse of x, palindrom(x) uses the first one, and main only walks…
- Global and local variablesVariabile globale și variabile localeA global variable (declared outside the functions) is visible from the whole program, starts automatically at 0 and keeps its value between calls. A…