Вопрос задан 16.02.2019 в 21:59. Предмет Информатика. Спрашивает Корсаков Никита.

Если трёхзначное число равно сумме кубов цифр, образующих это число, то такое число называется

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

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Назарчук Льоша.
Var i:integer;
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
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос