The oldest algorithm of history

Published 12-11-2010

I do not know if the title of this post is absolutely certain but is not thus little she needs. Memory that in the University spoke us of this algorithm, that goes back to the time of the Greeks and tries to divide to two numbers using only subtractions.


Briefly explained the algorithm it says that to divide To between coarse B with reducing €œB€ to successively to A without happening of 0. The number of times that has been realised the subtraction is the result of the division. The number that we have when deserts to reduce €œB€ because we would go of 0 is the remainder.


In pseudocode it would be:

bar to, b, result: whole numbers To read (a) To read (b) result = 0 While (a>=b) a = to - b;
result = result + 1;
FinMientras Escribir (result) To write (a)

And in php:

a=$_POST [€œto€];
b=$_POST [€œb€];
while (a>=b) \ {a=a-b;
resultado++;} I throw result;
I throw a;
Categories: Algorithms

It shares this article

It comments this article

© 2020 NonStop-Press - Sitemap