I believe that all of us seen or maybe even played darts. Everyone knows the circles which are numbered with points which you get by throwing the arrow. How could we calculate the result of our game if we get 10 points by hitting the center and then a minus one on each other circle on the darts board. And if we do not hit the board, we do not get any points which simply corresponds to zero.
Before going straight to programming we should analyze some different types of numbers.
The first one which I am introducing to you here is the Armstrong number. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, we could take 153 = 1^3 + 5^3 +3^3. There some other numbers which are written down at the bottom of post.
I was really disappointed of the lack of information about Pascal. I know that it is not very popular language now and there are many better languages around us. However, I do believe that many people need information and examples of Pascal tasks. Moreover, there are still some schools where students learn this language as their first programming experience.
Today I will try to introduce you with some fractures and how to divide them properly in Pascal.So the main point is to add some fractures and then get integer part and a new adjusted fracture.
I often used this function – a simple and clear to understand algorithm to find the greatest common divider of two numbers. Here is the whole code for that:
function greatest_common_divider(a, b:integer):integer;
while (a <> 0) AND (b <> 0) do
if a >= b
then a := a mod b
else b := b mod a;
greatest_common_divider := a + b;
I bet there’s no better way to do this on Pascal.