Перейти к основному содержанию
EDU-MMCS
Вы используете гостевой доступ (Вход)

Basic of programming

  1. В начало
  2. Курсы
  3. Воскресная математическая школа
  4. Лаборатория математического онлайн-образования мех...
  5. Basics of programming
  6. Topic 4. Procedures and Functions
  7. Labs and Tasks: Procedures

Labs and Tasks: Procedures

Требуемые условия завершения
Открыто с: суббота, 16 августа 2025, 00:00

Procedures: Parameterless and with Parameters

Lab 1, Procedures:

To do: Print 60 asterisks (*), each on a new line. Use a parameterless procedure.

✍Algorithm:


{0.3 points} Task 1, procedures:

To do: Create a procedure that takes two integers as arguments and returns their sum.

Note: The procedure signature must look like this:

procedure PrintSum(a, b: integer);

Expected output:

enter two numbers:
>>> 2  >>> 7
result: 2 + 7 = 9

[Program name: task-01-proc.pas]

{0.3 points} Task 2, procedures:

To do: Create a procedure that prints all integers from N down to 0 in a vertical list.

Note: The procedure signature must look like this:

procedure PrintIntegers(n: integer);

Expected output:

please, enter value of N: 
>>> 8
8 
7 
6 
5 
4 
3 
2 
1 
0

[Program name: task-02-proc.pas]

{0.4 points} Task 3, procedures:

To do: Create a procedure PrintSeq(A,B,C) (where A< b) that prints a sequence of numbers from A to B with a step of C.

Note: The procedure signature must look like this:

procedure PrintSeq(A,B,C: integer);

Expected output:

please, enter numbers A, B, C: 
>>> 2  >>> 9  >>> 2
2 4 6 8

[Program name: task-03-proc.pas]

{0.5 points} Task 4, procedures:

To do: Create a procedure that accepts a single integer argument and prints all divisors of that number.

Note: The procedure signature must look like this:

procedure PrintDivisors(numb: integer);

Expected output:

please, enter number: 
>>>18
1 2 3 6 9 18

[Program name: task-04-proc.pas]

Input and Output Parameters

Lab 2, procedures:

To do: Let's create a subroutine to calculate the average (arithmetic mean) of two entered integer values.

✍Algorithm:

Procedures: Swapping Variables

Lab 3, procedures:

To do: Create a procedure to swap the values of two variables.

Expected output:

a = 10
b = 12
Result:  a=12,  b=10

✍Algorithm:

Solution 1:

procedure Swap(var a, b: integer);
begin
  var t := a;
  a := b;
  b := t;
end;
 
begin
  var (x, y) := (3, 5);
  Swap(x, y); 
  println(x,y);
end.

Solution 2:

procedure Swap(var a, b: integer);
begin
  (a, b) := (b, a);
end;
 
begin
  var (x, y) := (3, 5);
  Swap(x, y); 
  println(x, y);
end.

Procedures with Parameters

{0.3 points} Task 5, procedures:

To do: Create a procedure PlusN(N, result) that computes N+N and stores the result in the result parameter (N is an input parameter, result is an output parameter).

Note: The procedure signature must look like this:

procedure PlusN(N : integer; var result: integer);

Expected output:

please enter an integer n
>>>5
result: 10

[Program name: task-05-proc.pas]

{0.4 points} Task 6, procedures:

To do: Create a procedure Power2N(N, powerN) that raises N to the power of powerN and stores the result in the result parameter (both N and powerN are input parameters, result is an output parameter).

Note: The procedure signature must look like this:

procedure PowerN(n, powerN: real; var result: real);

Expected output:

please enter number and exponent
>>>3  >>>4
3^4 = 81

[Program name: task-06-proc.pas]

{0.4 points} Task 7, procedures:

To do: Create a procedure FindMin(a,b,min) that compares two numbers a and b and stores the smallest value in the min parameter (a and b are input parameters, min is an output parameter).

Expected output:

enter two integers for a and b: 
>>>2 >>>6
min is 2

[Program name: task-07-proc.pas]

{0.4 points} Task 8, procedures:

To do: Create a procedure AddLeftDigit(D, K, res) that prepends a digit K (0≤K≤9) to the front of a number D (0≤D≤9) and passes the resulting number back to the calling program in the res parameter (D and K are input parameters, res is an output parameter).

Expected output:

enter values for D (0<=D<=9) and K(0<=K<=9):
>>>2  >>>4  
result: 42

[Program name: task-08-proc.pas]

{0.5 points} Task 9, procedures:

To do: Create a procedure FindSum(N,sum) that generates N random numbers, adds them together, and passes the sum back to the calling program in the sum parameter (N is an input parameter, sum is an output parameter).

Expected output:

Please, input how many numbers to add:
>>>5
generated numbers:
7 3 2 8 12
sum is 32

[Program name: task-09-proc.pas]

{1.5 points} * ExtraTask 10, procedures:

To do: Create a procedure AddLeftDigits(D, K1, K2, res1, res2) that first prepends digit K1 (0≤K1≤9) to the beginning of a positive integer D and stores the result in res1. Then prepend digit K2 to the intermediate result stored in res1 and pass the final result in res2.

Expected output:

Please, input  D,  K1 and K2 (0<=K<=9):
20   4   5  
>>> 204   2045 
---
342  7  1
>>> 3427   34271

[Program name: task-10-proc.pas]

◄ Procedures
Functions ►
Пропустить Навигация
Навигация
  • В начало

    • Страницы сайта

      • Мои курсы

      • Теги

    • Мои курсы

    • Курсы

      • Воскресная математическая школа

        • Открытое тестирование РНОМЦ и мехмата ЮФУ - 2025

        • Олимпиадная математическая школа

        • Повышение квалификации

        • Доступная математика

        • Лаборатория математического онлайн-образования мех...

          • Basics of programming

            • Общее

            • Topic 1. Basic constructions

            • Topic 2. Conditions

            • Topic 3. Loops

            • Topic 4. Procedures and Functions

              • СтраницаProcedures

              • ЗаданиеLabs and Tasks: Procedures

              • СтраницаFunctions

              • ЗаданиеLabs and Tasks: Functions

              • ЗаданиеLabs and Tasks: Functions as Algorithm Wrappers, A...

              • ЗаданиеLabs and Tasks: Recursion

            • Topic 5. Arrays

          • Тест - модуль

          • Функции

          • Алгоритмы - I

          • Основы ЭО

          • Higher Math Intro

          • Основы программирования

        • Осенняя универсиада

        • Научно-практическая конференция

        • ВМШ

          • ВМШ - 24

        • Летняя олимпиадная математическая школа РНОМЦ и ме...

        • ОМШ мехмата ЮФУ

        • ЗФТШ - 2021-2022

      • Осенний семестр

        • Прикладная математика и информатика

        • Фундаментальная информатика и ИТ

        • Математика, механика

        • Педагогическое образование

        • Магистратура

          • Разработка мобильных приложений и компьютерных игр

        • Аспирантура

        • Вечернее отделение

        • Другое

      • Весенний семестр

        • Прикладная математика и информатика

        • Фундаментальная информатика и ИТ

        • Математика, механика

        • Педагогическое образование

        • Магистратура

          • Разработка мобильных приложений и компьютерных игр

        • Аспирантура

        • Вечернее отделение

        • Другое

      • Воскресная компьютерная школа

        • Пользователь компьютера плюс

        • Пользователь прикладных программ

        • Программирование I ступень

        • Программирование II ступень

        • Программирование III ступень

        • Архив

      • Государственная итоговая аттестация

      • Дополнительное образование

      • Олимпиады

      • Видеолекции

      • Разное

      • Архив курсов

      • Заочная школа мехмата ЮФУ

Служба поддержки сайта
Вы используете гостевой доступ (Вход)
Basics of programming
Сводка хранения данных
Скачать мобильное приложение Яндекс.Метрика