Вопрос задан 21.02.2019 в 20:47. Предмет Информатика. Спрашивает Аверьянов Лёня.

10. Авmoморфные числа. Натуральное число называется автоморфным, если оно равно последним цифрам

своего квадрата. Например: 25 и 625. Напишите программу, которая вводит натуральное число N и выводит на акран все автоморфные числа, не превосходящие N.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Олофинская Вика.
Var n,i,l:integer; s1,s2:string; 
begin
write('n = '); readln(n);
for i:=1 to n do
 begin
 str(i,s1);
 l:=length(s1);
 str(i*i,s2);
 if s1=copy(s2,length(s2)-l+1,l) then writeln(i,'  ',i*i);
 end;
end.

Пример:
n = 10000
1  1
5  25
6  36
25  625
76  5776
376  141376
625  390625
9376  87909376
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Program to Find Automorphic Numbers

To create a program that inputs a natural number N and outputs all automorphic numbers not exceeding N, we can use the following Python code:

```python def is_automorphic(num): square = num * num return str(square).endswith(str(num))

def find_automorphic_numbers(N): automorphic_nums = [num for num in range(1, N+1) if is_automorphic(num)] return automorphic_nums

N = int(input("Enter a natural number N: ")) automorphic_numbers = find_automorphic_numbers(N) print("Automorphic numbers not exceeding", N, "are:", automorphic_numbers) ```

This program defines a function `is_automorphic` to check if a number is automorphic and another function `find_automorphic_numbers` to find all automorphic numbers not exceeding N. It then takes user input for N and prints the automorphic numbers.

Explanation of the Program

- The program first defines a function `is_automorphic` to check if a number is automorphic by squaring the number and checking if the square ends with the original number. - It then defines a function `find_automorphic_numbers` to iterate through numbers from 1 to N and find all automorphic numbers using the `is_automorphic` function. - After that, it takes user input for N and calls the `find_automorphic_numbers` function to find automorphic numbers not exceeding N and prints the result.

Feel free to try running this program with different values of N to see the automorphic numbers it generates!

0 0

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

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

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