Exemplos de algoritmos en varias linguaxes
Este artigo ilustra algúns exemplos en varias linguaxes de programación para ilustrar a sintaxe de cada unha. O algoritmo implementado é simplemente facer a suma entre dous valores.
C/C++/Java/C#[editar | editar a fonte]
int SumaDeDousValores (int A, int B)
{
return ( A + B );
}
Visual Basic[editar | editar a fonte]
function SumaDeDousValoresEnteiros(a as integer, b as integer) as integer
SumaDeDousValores=a+b
end function
Pascal[editar | editar a fonte]
function SumaDeDousValoresInteiros( A, B: Integer ): Integer;
var Resultado : Integer;
begin
Resultado := A + B;
SumaDeDousValoresInteiros := Resultado;
end;
Delphi[editar | editar a fonte]
function SumaDeDousValores( A, B: Integer ): Integer;
begin
Result := A + B;
end;
Python[editar | editar a fonte]
def SumaDeDousValores (a, b):
return a + b
Scheme[editar | editar a fonte]
(define Suma (lambda (x y) (+ x y)) )
Haskell[editar | editar a fonte]
suma :: Integer -> Integer -> Integer -- (asinatura) suma a b = a + b
Logo[editar | editar a fonte]
defina "SumaDeDousValores [[a b]] [escriba suma :a :b]]
Action Script[editar | editar a fonte]
function sumaDeDousValores (a, b){
trace(a + b);
};
PHP[editar | editar a fonte]
function SumaDeDousValores($VlrA, $VlrB)
{
return ($VlrA + $VlrB);
}