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

cs101 ОП / Basics of programming ENG

  1. В начало
  2. Курсы
  3. Осенний семестр
  4. Фундаментальная информатика и ИТ
  5. cs101 ENG
  6. 1 topic. Basic constructions and loops
  7. Lesson #2. Integers, div and mod operators

Lesson #2. Integers, div and mod operators

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

Introduction

Div operation is an integer division, where the result is rounded.

The div operation calculates the integer part of the result of dividing integers (partial qúotient ). For example:

10 div  2 = 5
22 div  7 = 3
65 div 10 = 6

The result of N div K shows how many times K «fits inside» N.

The mod operation calculates the remáinder from dividing one integer by another. In this case, if the numbers are divided évenly the remainder is zero. Example:

10 mod  2 = 0
22 mod  7 = 1
65 mod 10 = 5

The result of N mod K shows that "remains of N" after the maximum number of pieces of size K is "thrown" out of it.

By parsing any integer N into two components - the quotient d and the remainder m, using the same divisor K and operations div and mod, you will then easily restore this number by the formula:

1

 Examples

10 div  2 = 5, 10 mod  2 = 0    =>   10 =  5*2 + 0
22 div  7 = 3, 22 mod  7 = 1    =>   22 =  3*7 + 1
65 div 10 = 6, 65 mod 10 = 5    =>   65 = 6*10 + 5

Stándard Form Of A Number

Any number can be disassembled into digits using powers of 10 and specified operations. This rule is called the stándard form of a number:

123 = 1*100 + 2*10 + 3

e.g. So to make some digit to be hundreds you need to myltiple it by 100 (for digit 2 we have 2 * 100 = 200).

3 Rules To Get Digits Of Three-Digit Integer

It can be seen that:
  1. to get hundreds (first digit) of three-digit numbers you need to calculate the quotient of division this number by 100 (number div 100: 123 div 100 = 1)
  2. to get tens (second digit) you need to calculate the remainder of the division this number by 100, and then - the quotient of division the result by 10 (1. number mod 100: 123 mod 100 = 23; 2. 23 div 10 = 2) (also there is another way)
  3. to get units (third digit), you need to calculate remainder of dividing this number by 10 (number mod 10: 123 mod 10 = 3).
  4. For numbers of other bit width, these algorithms can change.

Tasks (div and mod)

Follow the rules:

  • Save your files with the names of the task (e.g. task-04.pas)
  • Give meaning names to your variables
  • Use the comments to make the program clear for user
  • Give the task of the program in the form of a comment before the program code. For comments use curly brackets: 
  • 1
  • Give the results of your program (log) in the form of a comment after the program code. It’s easy to do by simply copying. For comments use curly brackets:

    1

[task-001.pas] A distance L in centimeters is known. Use the operation of integer division to find number of meters of the distance (1 meter = 100 centimeters). Use the comments to make the program clear for user. Give the log of your program in the form of a comment after the program code.

[task-002.pas] A mass in kilo is known. Use the operation of integer division to find the number of ton (1 ton = 1000 kilo). Use the comments to make the program clear for user. Give the log of your program in the form of a comment after the program code.

1. [task-01.pas] A person's age specified in months is given. Determin a person's age in years (e.g: 65 months is 5 full years, 24 months is 2 years). Check the correctness of your program, give the log in the form of a comment.

2. [task-02.pas] A two-digit integer is known. Output its right and left digits séparated by commas.

example:
-35 >>> 5, 3
90 >>> 0, 9

Note. Run the program and enter a non-two-digit number. What has happened? Is the result right? Later we will learn how to perform validation of the input data.

3. [task-03.pas] A two-digit integer is known. Output the addition and the multiplacation of its digits. Check the correctness of your program, give the log in the form of a comment.

example:
 35 >>> 8, 15
 90 >>> 9, 0
-11 >>> 2, 1

Note. Each digit of the number will be needed twice: in the calculation of the sum — the first time and in the calculation of the multiplacation — the second time. It is recommended to use auxíliary variables for storing the values of the digits.

4. [task-04.pas] A three-digit integer is known. Output all of its digits (the order does not matter). Check the correctness of your program, give the log in the form of a comment.

example:
-105 >>> 5, 0, 1
or
-105 >>> 1, 0, 5

5. [task-05.pas] A three-digit integer is known. Output the addition of its digits. Make sure that your program works correctly with negative numbers.

6. [task-06.pas] Two digits from 0 up to 9 are given. Use the standard form of a number to make a number, the digits of which are the specified digits.

example:
3, 5 >>> 35
7, 0 >>> 70
0, 4 >>> 4

7. [task-07.pas] A two-digit integer is known. Swap the digits of tens and units (left and right digits) in this number. Check the correctness of your program, give the log in the form of a comment.

example:
 35 >>>  53
-10 >>> -1

8. [task-08.pas] A three-digit integer is known. Swap the digits of hundreds and tens in this number (left and middle digits). Check the correctness of your program, give the log in the form of a comment.

9. [task-09.pas] A three-digit integer is known. Perform a cýclic shift of digits to the left (the digit of units becomes the digit of tens, the digit of tens becomes the digit of hundreds and the digit of hundreds becomes the digit of units).

example:
 123 >>>  231
-602 >>> -26

10. [task-10.pas] A three-digit integer is known. Perform a cýclic shift of digits to the right .

◄ Lesson #1. Introduction to PascalABC.NET
Lesson #3. Boolean Expressions And Conditions ►
Пропустить Навигация
Навигация
  • В начало

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

      • Мои курсы

      • Теги

    • Мои курсы

    • Курсы

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

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

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

          • Compiler Development

          • CMVSM

          • АЗПК

          • Frontend

          • ТеорЯП

          • Ruby Eng

          • EngCA&OS

          • CS201e

          • Компиляторы - лекции

          • CS202

          • CS211 C++ ENG

          • cs101 ENG

            • Общее

            • 1 topic. Basic constructions and loops

              • ЗаданиеLesson #1. Introduction to PascalABC.NET

              • ЗаданиеLesson #2. Integers, div and mod operators

              • ЗаданиеLesson #3. Boolean Expressions And Conditions

              • ЗаданиеLesson #4. Condition operator & branches. IF s...

              • ЗаданиеLesson #5. IF statement Part II. Max and Min

              • ЗаданиеHometask (until 6/10)

              • ЗаданиеFormatted output using WritelnFormat

              • ЗаданиеLesson #6. Chained IF statements and Case statemen...

              • ЗаданиеLesson #7. Loops

              • ЗаданиеLesson #8. For Loop

              • ЗаданиеLesson #9. Sum, Accumulators, Product and Counter....

              • ЗаданиеLesson #10. Minimum or Maximum value of N numbers

              • ЗаданиеLesson #11. While & Repeat Loops

              • ЗаданиеLesson #12. While & Repeat Loops: digits of a ...

              • ЗаданиеLesson #13. Procedures

              • ЗаданиеLesson #14. Functions

              • ЗаданиеTest Loops (control test)

            • Тема 2

            • Тема 3

            • Тема 4

            • Тема 5

            • Тема 6

            • Тема 7

            • Тема 8

            • Тема 9

            • Тема 10

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

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

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

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

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

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

        • Другое

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

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

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

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

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

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

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

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

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

        • Другое

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

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

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

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

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

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

        • Архив

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

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

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

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

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

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

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

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

        • ВМШ

          • ВМШ - 24

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

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

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

      • Олимпиады

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

      • Разное

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

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

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