Created
April 21, 2025 19:18
-
-
Save Grimitch/a883dea05368f50cd31b6032c6013cfa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) | |
#include <iostream> | |
void print(int n) { | |
if (n == 0) return; | |
print(n - 1); | |
std::cout << n << " "; | |
2) | |
#include <iostream> | |
void AB(int a, int b) { | |
std::cout << a << " "; | |
if (a == b) return; | |
if (a < b) AB(a + 1, b); | |
else AB(a - 1, b); | |
} | |
3) | |
bool num(int n) { | |
if (n == 1) return true; | |
if (n % 2 != 0 || n == 0) return false; | |
return num(n / 2); | |
} | |
4) | |
int digit(int n) { | |
if (n == 0) return 0; | |
return n % 10 + digit(n / 10); | |
} | |
5) | |
#include <iostream> | |
void digit(int n) { | |
std::cout << n % 10 << " "; | |
if (n >= 10) digit(n / 10); | |
} | |
6) | |
#include <iostream> | |
void digit(int n) { | |
if (n < 10) { | |
std::cout << n << " "; | |
return; | |
} | |
digit(n / 10); | |
std::cout << n % 10 << " "; | |
} | |
7) | |
int numrtevers(int n, int rev = 0) { | |
if (n == 0) return rev; | |
return numrtevers(n / 10, rev * 10 + n % 10); | |
} | |
8) | |
bool Palindrom(const char* s, int left, int right) { | |
if (left >= right) return true; | |
if (s[left] != s[right]) return false; | |
return Palindrom(s, left + 1, right - 1); | |
} | |
9) | |
int fib(int n) { | |
if (n <= 1) return n; | |
return fib(n - 1) + fib(n - 2); | |
} | |
10) | |
int stupin(int base, int num) { | |
if (num == 0) return 1; | |
return base * stupin(base, num - 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment