
10. Авmoморфные числа. Натуральное число называется автоморфным, если оно равно последним цифрам
своего квадрата. Например: 25 и 625. Напишите программу, которая вводит натуральное число N и выводит на акран все автоморфные числа, не превосходящие N.

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

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



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!


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