c++ - call a function recusively and store it into an int gives me 1? -
this code runs fine , used find largest factor between 2 numbers, wanted know why num prints out (for example 1 1 1 3 @ end of program). confused why can store function int , number? why give 1?
#include <iostream> using namespace std; int largestfactor(int number, int start) { if(start == number) return 1; int num = largestfactor(number, start+1); cout << num; if (num ==1 && number % start == 0) return start; return num; } int main() { largestfactor(6,2); }
Comments
Post a Comment