Enters 32/64 bits amb complement a 2.
Exemples: 0
, 3
, 28
, (- 55)
.
Operacions:
+
// Comptar el nombre de lletres A en un text. | |
// => Recorregut | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int n = 0; | |
char c; | |
while (cin >> c) { |
// Funció recursiva que retorna el factorial d'un natural. | |
// Prec: n>=0. | |
int factorial(int n) { | |
if (n == 0) return 1; | |
else return n * factorial(n - 1); | |
} |
# Floc de Koch | |
# (vegeu https://en.wikipedia.org/wiki/Koch_snowflake) | |
import turtle # https://docs.python.org/3.6/library/turtle.html | |
# pinta el segment bàsic de Koch _/\_ amb segments de llargada long i passos passes recursives | |
def figura(long, passos): | |
if passos == 1: | |
turtle.forward(long) |
-- Diccionari de Strings a Ints amb funcions d'ordre superior | |
-- i valors per defecte. | |
type Dict = (String -> Int) | |
-- Versió 1 | |
create :: Int -> Dict | |
create def = \key -> def |
// Dir si un text és palíndrom | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
bool palindrom(const string& s) { // string s també estaria bé | |
int esq = 0; |
// Cerca lineal en un vector | |
#include <iostream> | |
#include <vector> | |
#include <cstdlib> // permet usar el rand() i el srand() | |
#include <ctime> // permet usar el time() i el clock() | |
using namespace std; | |