
Если трёхзначное число равно сумме кубов цифр, образующих это число, то такое число называется
«магическим». Найти и вывести все «магические числа». (Написать функцию вычисления суммы кубов цифр трёхзначного числа). Паскаль, через функции пользователя.

Ответы на вопрос

function sum(n:integer):integer;
var n1,n2,n3:integer;
begin
n1:=n div 100;
n2:=n div 10 mod 10;
n3:=n md 10;
sum:=n1*n1*n1+n2*n2*n2+n3*n3*n3;
end;
begin
writeln('Магические числа:');
for i:=100 to 999 do
if i=sum(i) then writeln(i);
end.
Результат:
Магические числа:
153
370
371
407



Finding "Magical" Numbers
To find and display all "magical" numbers, we need to write a function to calculate the sum of the cubes of the digits of a three-digit number. Once we have this function, we can use it to check all three-digit numbers and identify the "magical" ones.
Here's a Pascal function to calculate the sum of the cubes of the digits of a three-digit number:
```pascal function SumOfCubesOfDigits(n: integer): integer; var digit, sum: integer; begin sum := 0; while n > 0 do begin digit := n mod 10; sum := sum + digit * digit * digit; n := n div 10; end; SumOfCubesOfDigits := sum; end; ```
This function takes a three-digit number as input and returns the sum of the cubes of its digits.
Next, we can use this function to find and display all "magical" numbers. We'll iterate through all three-digit numbers, calculate the sum of the cubes of their digits, and check if it equals the original number. If it does, we'll consider it a "magical" number and display it.
Let's proceed with implementing the function and displaying the "magical" numbers.


Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili