Lezione 1

in C
#include <stdio.h>

void primes(int n) {
int i = 0;
for (i = 0; i<n; i++) {
if (i%2 != 0 && i%3 != 0) {
printf ("%d ",i);
}
}
}

int main(void) {
primes(100);
return 0;
}

in Python:
#! /usr/bin/env python

1. Questo e un commento

def primes(n) :
"""Qua fai commentare cosa e questo funzione"""
result = []
for x in xrange(n) :
if x%2 != 0 and x%3 != 0 :
result.append(x)
return result

def funcprimes(n) :
return [x for x in xrange(n) if x%2 != 0 and x%3 != 0]

def primedivisors(n) :
return [(x,n/x) for x in funcprimes(int(n**0.5)+1) if n%x == 0 and n/x in set(funcprimes(n+1))]

print primes(100)
print funcprimes(100)
print primedivisors(100)

In Prolog:
fibo_td(0,0).
fibo_td(1,1).
fibo_td(N,F):-
N>1, N1 is N-1, N2 is N-2,
fibo_td(N1,F1), fibo_td(N2,F2),
F is F1+F2.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.