Skip to content

Commit d9f35ad

Browse files
authored
PCL: add gcd and digits_sum programs (#91)
* Add `gcd.pcl` program with links to .input and .result files * Add `digits_sum.pcl` program with .input and .result files
1 parent ec245a5 commit d9f35ad

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

pcl/programs/digits_sum.input

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026

pcl/programs/digits_sum.pcl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
program digits_sum;
2+
3+
var num, sum, temp : integer;
4+
5+
begin
6+
writeString("Enter a positive integer: \n");
7+
num := readInteger();
8+
9+
sum := 0;
10+
temp := num;
11+
12+
while temp > 0 do
13+
begin
14+
sum := sum + (temp mod 10);
15+
temp := temp div 10
16+
end;
17+
18+
writeString("The sum of the digits of ");
19+
writeInteger(num);
20+
writeString(" is ");
21+
writeInteger(sum);
22+
writeString("\n")
23+
end.

pcl/programs/digits_sum.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Enter a positive integer:
2+
The sum of the digits of 2026 is 10

pcl/programs/gcd.input

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../alan/programs/gcd.input

pcl/programs/gcd.pcl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
program gcd;
2+
3+
var a, b : integer;
4+
5+
function gcd (x, y : integer) : integer;
6+
begin
7+
if y = 0 then
8+
result := x
9+
else
10+
result := gcd(y, x mod y)
11+
end;
12+
13+
begin
14+
writeString("Give me two positive integers: \n");
15+
a := readInteger();
16+
b := readInteger();
17+
writeString("\nTheir GCD is: ");
18+
writeInteger(gcd(a, b));
19+
writeString("\n")
20+
end.

pcl/programs/gcd.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../alan/programs/gcd.result

0 commit comments

Comments
 (0)