Создай учебные задачи на различных языках программирования: различия между версиями
Материал из Поле цифровой дидактики
Patarakin (обсуждение | вклад) |
Patarakin (обсуждение | вклад) |
||
Строка 20: | Строка 20: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
; Sure, here are 5 tasks that involve recursion in programming: | |||
# Task 1: Write a recursive function to calculate the nth Fibonacci number. The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two. | |||
# Task 2: Write a recursive function to reverse a string. For example, "hello" should become "olleh". | |||
# Task 3: Write a recursive function to calculate the sum of digits in an integer. For example, if the input is 1234 then output should be 10 since (1+2+3+4) = 10. | |||
# Task 4: Implement binary search algorithm using recursion on a sorted list of integers. | |||
# Task 5: Write a program that finds all possible combinations of k numbers from n numbers using recursion. |
Текущая версия на 18:57, 5 июня 2023
Описание | Генератор учебных задач на различных языках программирования |
---|---|
Область знаний | Информатика |
Тип генерируемого контента | Код, Текст |
Ссылка на пример | https://ora.ai/patarakin/scratch-tasks |
Сценарий генерации |
|
Среды для генерации: | Ora, ChatGPT, PerplexityAI |
def iterative_factorial(n):
result = 1
for i in range(1,n+1):
result *= i
return result
print(iterative_factorial(6))
- Sure, here are 5 tasks that involve recursion in programming
- Task 1: Write a recursive function to calculate the nth Fibonacci number. The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two.
- Task 2: Write a recursive function to reverse a string. For example, "hello" should become "olleh".
- Task 3: Write a recursive function to calculate the sum of digits in an integer. For example, if the input is 1234 then output should be 10 since (1+2+3+4) = 10.
- Task 4: Implement binary search algorithm using recursion on a sorted list of integers.
- Task 5: Write a program that finds all possible combinations of k numbers from n numbers using recursion.