Algol (short for Algorithmic Language) is a high-level programming language that was developed in the late 1950s. It was one of the first languages designed for scientific and engineering computations. In this article, we will show you how to write a program in Algol that calculates the factorial of a given number.
Factorial is a mathematical operation that multiplies a number by all the numbers below it. For example, the factorial of 5 (written as 5!) is calculated as:
5! = 5 x 4 x 3 x 2 x 1 = 120
To calculate the factorial of a number using Algol, we will use a loop to multiply the number by all the numbers below it. Here is the algorithm:
- Start with a variable n, which is the number whose factorial we want to calculate.
- Initialize a variable called result to 1.
- Use a loop to multiply result by all the numbers from 1 to n.
- Return the result.
Now let’s write the program in Algol:
begin
integer n, result, i;
write("Enter a number: ");
read(n);
result := 1;
for i := 1 step 1 until n do
result := result * i;
write("Factorial of ", n, " is ", result);
end.
In this program, we first declare three variables: n, result, and i. n is the input number whose factorial we want to calculate, result is the variable that will hold the final result, and i is a loop counter.
We then prompt the user to enter a number and read it into the variable n.
Next, we initialize the variable result to 1, as we will be multiplying it by all the numbers below n.
We then use a for loop to multiply result by all the numbers from 1 to n. The loop starts at 1 and increments i by 1 until i is equal to n.
Finally, we print out the result.
Let’s try running the program with n = 5:
Enter a number: 5
Factorial of 5 is 120
As you can see, the program correctly calculates the factorial of 5 to be 120.
In conclusion, writing a program to calculate the factorial of a number using Algol is a straightforward process. By using a loop to multiply the number by all the numbers below it, we can calculate the factorial of any number.
Algol is a language that is known for its simplicity and clarity. It was designed to be easy to read and write, making it a popular language for scientific and mathematical calculations. Algol has had a significant impact on the development of computer science, and many of its concepts are still used in modern programming languages.

When writing a program in Algol, it is important to remember that Algol uses a block structure. Each block consists of a sequence of statements enclosed in braces. Blocks can be nested, with the inner blocks being contained within the outer blocks.
Algol also uses a structured programming approach, which emphasizes the use of control structures such as loops and conditional statements. This makes Algol code easier to read and understand, as it follows a logical structure.
Here’s an example of a program in Algol that uses a conditional statement:
begin
integer age;
write("Enter your age: ");
read(age);
if age >= 18 then
write("You are an adult.");
else
write("You are a minor.");
fi
end.

In this program, we declare an integer variable called age and prompt the user to enter their age. We then use an if statement to check if the age is greater than or equal to 18. If it is, we print “You are an adult.” If it is not, we print “You are a minor.”
Algol also supports functions, which are a set of statements that perform a specific task. Functions can be called from within other parts of the program, making them useful for organizing code and reducing repetition.
Here’s an example of a program in Algol that uses a function to calculate the sum of two numbers:
begin
integer x, y;
write("Enter the first number: ");
read(x);
write("Enter the second number: ");
read(y);
write("The sum is ", sum(x, y));
end.
function sum(a, b: integer) : integer;
begin
return a + b;
end.
In this program, we declare two integer variables called x and y, prompt the user to enter two numbers, and then call the sum function to calculate the sum of the two numbers. The function takes two integer arguments and returns their sum.
Overall, Algol is a powerful and flexible programming language that is well-suited for scientific and mathematical calculations. Its simple syntax and structured programming approach make it easy to learn and use, while its support for functions and control structures allows for the creation of complex programs.
[…] Read moreA Program That Calculates the Factorial of a Given Number in Algol […]
[…] In Algol, implementing the quick sort algorithm is relatively straightforward. Here’s an example program that sorts a list of numbers using quick sort: […]
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.com/ru-UA/register?ref=JHQQKNKN
Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/es/register?ref=T7KCZASX
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.com/kz/register-person?ref=GJY4VW8W
At the beginning, I was still puzzled. Since I read your article, I have been very impressed. It has provided a lot of innovative ideas for my thesis related to gate.io. Thank u. But I still have some doubts, can you help me? Thanks.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.com/ph/register?ref=WTOZ531Y
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/kz/register-person?ref=V2H9AFPY
Your enticle helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/en/register-person?ref=P9L9FQKY
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.com/en/register?ref=RQUR4BEO
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.com/lv/register-person?ref=W0BCQMF1
Your article helped me a lot, is there any more related content? Thanks! https://www.binance.com/zh-TC/register?ref=GJY4VW8W