sum 0;
x 1;
while x N do
sum sum + x;
x x + 1;
end while
print sum;
Algorithm Sum N numbers in a list (or array) named values
sum 0;
index 1;
while index N do
sum sum + values[index ];
index index + 1;
end while
print sum;
Algorithm Divide a = a1a2 · · · aN by d using long division
B1 a1 {Bi is what we divide d into in step i}
i 1
while i N do
qi largest integer such that d × qi Bi; {qi is the ith digit of the quotient q}
if i N − 1 then
Bi+1 10 × (Bi − d × qi) + ai+1
end if
i i + 1;
end while
r BN − d × qN {r is the remainder}
Sunday, May 2, 2010
Subscribe to:
Posts (Atom)
