Set1 Algorithms
Set1 Algorithms
function y = myFactorial(n)
% computes y = n!
y = 1;
for i=2:n
y = y*i;
end
Alternatively
function y = myFactorial(n)
x = 1:n;
y = prod(x);
Alternatively (recursive version)
function y = myFactorial(n)
if n == 1
y = 1;
else
y = myFactorial(n-1)*n;
end
function [t B] = SignedBinaryInt(b)
% b = [b1 , b2 , b3, b4] is a row vector of 4 binary bits
% t = b(1) is the sign of a binary integer B
% B is the binary integer +b2b3b4 0r b2b3b4
t = b(1);
B = b(2:4);
if t == 1
B=[ = ', num2str(B)];
elseif t == 0
B=[ + ', num2str(B)];
end