Relative Content

Tag Archive for c#recursion

I want my 2nd if-statement to do a recursion-type loop but it is not returning anything and defaulting to false, what am i doing wrong?

bool isPalindrome(string some_string) { if (some_string.length() == 0 || some_string.length() == 1) { return true; } if (some_string[0] == some_string[some_string.length() – 1]) { return isPalindrome(some_string.substr(1, some_string.length() – 1)); } else { return false; } } First off, this code is to check if a string is palindrome or not. I looked up some links and […]

Generate recursive negative fibonacci series

enter image description hereWAP to generate negative Fibonacci numbers using recursion, Description:
In mathematics, the Fibonacci numbers or Fibonacci sequence are the numbers in the following integer sequence 0, 1, -1, 2, -3, 5, -8, 13, -21, 34, -55, 89, -144 . . .
By definition, the first two numbers in the Fibonacci sequence are 0 and 1, each subsequent number is the subtraction of the previous two
Pr-requisites:
Arithmetic Operators
Recursions
Objective: –

Change recursive into iterativefunction

I got a recursive function for exporting information and I want to transform it into an iterative one for efficiency reasons (toy problem below). However, as there are statements in the recursive function after the call of the recursive function, I do not obtain a working iterative solution.

print the multiples of given number recursively

#include <iostream> using namespace std; int multiples(int n, int m) { if (m < 1) { return 0; } cout << multiples(n, m – 1) << ” ” << n * m; } int main() { multiples(3, 4); return 0; } I am trying to print the multiples of given number recursively in C++ but […]

Getting out of looping (recursion)

When creating a division, the method does not find a director, it creates one, but then tries to create a division again, and so on in a circle. How can I get out of this recursion?