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

cs101 ОП / Basics of programming ENG

  1. В начало
  2. Курсы
  3. Осенний семестр
  4. Фундаментальная информатика и ИТ
  5. cs101 ENG
  6. 1 topic. Basic constructions and loops
  7. Lesson #12. While & Repeat Loops: digits of a ...

Lesson #12. While & Repeat Loops: digits of a number

Требуемые условия завершения
Открыто с: среда, 6 ноября 2019, 00:00
Срок сдачи: пятница, 13 декабря 2019, 00:00

Lections

Sum of digits of natural number

Task: Natural number m is given. Calculate the sum of its digits.

m=425
result: 11 

********************************************************************************************

✎

1. {0.3 points}[L12-task-01.pas] An integer is given (variable a). Find the number of its digits and their sum.

For example:

Example1:
N = 1205 >>> Count = 4, Sum = 8
Example2:
N = -111 >>> Count = 3, Sum = 3

*******************************************************************************************************

Quantity of natural number digits satisfying some condition

Task: Natural number m is given. How many "1" digits in its decimal representation does it have?


m=4121
result: 2

*******************************************************************************************

✎

2. {0.3 points}[L12-task-02.pas]  Natural number m is given. Calculate the sum of its odd digits.

For example:

m = 136
result: 2 

3. {0.3 points}[L12-task-03.pas]  Natural number m is given. Calculate the sum of its digits that are divisible by 3.

For example:

Example1:
N = 1309 >>> digits: 3, 9; their sum: 12
Example2:
N = -123 >>> digits: 3; their sum: 3
Example3:
N = -623 >>> digits: 6, 3; their sum: 9

4. {0.4 points}[L12-task-04.pas] An integer is given. Output its digits, starting with the last digit (from right to left).

For example:

Example1:
N = 1205 >>> 5, 0, 2, 1
Example2:
N = -123 >>> 3, 2, 1
Example3:
N = -111 >>> 1, 1, 1

5. {0.4 points}[L12-task-05.pas] A sequence of 4 digits is given. Form a positive number consisting of these digits, starting with the last digit (from right to left).

For example:

Example1:
3, 7, 0, 2 >>> number = 2073
Example2:
2, 1, 4, 3  >>> number = 3412

6. {0.6 points}[L12-task-06.pas] A natural number N which is the quantity of the digits of some number is given; and also the digits themselves are given. Form a positive number consisting of these digits.

For example:

Example1:
N = 3; digits = 3,7,0 >>> number  = 370
Example2:
N = 5; digits = 0,7,0,1,6 >>> number  = 7016
Example3:
N = 1; digits = 2     >>> number  = 2
Example4:
N = 2; digits = 0,2   >>> number = 2

7. {0.6 points}[L12-task-07.pas] An integer is given. Output the value of the largest digit of this number.

For example:

Example1:
N =  50 >>> MaxDig = 5
Example2:
N = 1946 >>> MaxDig = 9
Example3:
N =  -13 >>> MaxDig = 3

8. {1.0 points}[L12-task-08.pas] An integer is given. Output the value of the lowest digit of this number and also output its position. Try to use only one loop in the solution.

For example:

Example1:
N =  -50 >>> MinDig = 0, Pos = 2
Example2:
N =  13 >>> MinDig = 1, Pos = 1
Example3:
N = 8287 >>> MinDig = 2, Pos = 2

9. {0.7 points}[L12-task-9.pas] Two integers are given. Form a new number which begins with the digits of the first integer and finishes with the digits of the second integer.

For example:

Example1:
N1 =  1, N2 = 390 >>> number = 1390
Example2:
N1 =   10, N2 = 21 >>> number = 1021
Example3:
N1 =  72, N2 =   2 >>> number = 722 
*********************************************************************

The problem of finding a value

Task. N numbers are given. Is there a number k among them?

Solution. Let's define logical variable Exists, Initialized by False value in the beginning. Then In a loop we will change it into "True" value if there is any number equals k.

  println('please, input a number to find');
  var k:=readInteger; 

println(Exists);
Example1:
please, input a number to find
k = 6
n = 3
x: 12  7  6
exists = true

Example2:
please, input a number to find
k = 5
n = 4
x: 12  7  6  8
exists = false

***********************************************************************
✎

10. {0.5 points}[L12-task-10.pas] An integer N and a digit D are given. Output True if there is the digit D in the number N, and output False otherwise.

For example:

Example1:
N = 291, D = 9 >>> True (there is digit 9 in the number 291)
Example2:
N = 1234, D = 9 >>> False (there is no digit 9 in the number 1234)
****************************************************************

Break & Continue statements

When a program executes a break statement which is inside a loop, it stops immediately and the program runs the next statement after the loop.

When a program executes a continue statement which is inside a loop, the current iteration of the loop is immediately terminated and the program runs the next iteration of the loop.

break и continue statements can be used only in loops

The problem of finding a value with break

Task. N numbers are given. Is there a number k among them?

Solution. Let's define logical variable Exists, Initialized by "False" value in the beginning. Then In a loop we will change it into "True" value if there is any number equals k. And If the value is found, we break the loop

  var k := readInteger;

***************************************************************

✎

11. {0.5 points}[L12-task-11.pas] An integer N and a digit D are given. If there is the digit D in the number N , output True, otherwise output False. Use a break statement.

For example:

Example1:
N = 291, D = 9 >>> True (there is digit 9 in the number 291)
Example2:
N = 1234, D = 9 >>> False (there is no digit 9 in the number 1234)

12. {0.5 points}[L12-task-12.pas]An integer N is given. If there is even digit among the digits of the number N , output True, otherwise output False. Use a break statement.

For example:

Example1:
N = 2914 >>> True 
Example2:
N = 1931 >>> False 
◄ Lesson #11. While & Repeat Loops
Lesson #13. Procedures ►
Пропустить Навигация
Навигация
  • В начало

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

      • Мои курсы

      • Теги

    • Мои курсы

    • Курсы

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

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

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

          • 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
Сводка хранения данных
Скачать мобильное приложение Яндекс.Метрика