title: Finding the smallest prime factor using recursion c++
body: <p>I am new to c++ and I have been tasked to write a code which finds the smallest prime factor of a number using recursion. If N is less than 2 the code should return 1. If N is a prime number itself the code should return N. Otherwise the code should return the smallest prime factor of N. I have attempted the question but I have used a for loop to check for the lowest prime factor and I am unsure if this method in the context of my answer is iterative or recursive. To call the function for main the user should enter lowestPrimeFactor(x);, where x is the number they want to find the lowest prime factor for. I am stuck with trying to change the iterative section to recursive, where the code checks for the lowest prime factor. I would appreciate any feedback.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;math.h&gt;
  long lowestPrimeFactor(long N, long i=2) {
      if(N&lt;2){  //if N is less than 2, return 1
          std::cout &lt;&lt; 1; //print to screen to check
          return 1;
      }
  
      bool isPrime =true; //Check if number is prime
      for(i=2;i&lt;=N/2; ++i){
          if(N%i==0){
              isPrime=false;
              break;
          }
      }
          if (isPrime){
              std::cout&lt;&lt;N;
              return N;
          }
  
          for (int i = 3; i* i &lt;= N; i+=2){ //This is where I am unsure how to translate to recursive as it is based of an iterative solution
                  if(N%i == 0)
                  std::cout&lt;&lt;i;
                  return i;
      }
  
  
  //Driver code to check functionality
  int main(){
  lowestPrimeFactor(19);
  }
  
  
  </code></pre>
  
  <p>EDIT
  I think I have modified the code correctly to be recursive for the prime factor check </p>
  
  <pre><code>        //Recursive
          if(i*i&lt;=N){
              N%i==0; lowestPrimeFactor(i);
          }
          else return i;
  </code></pre>
  
  <p>Just need to try and adjust the bool part to be recursive too</p>