Last active
September 17, 2015 10:12
-
-
Save phamtm/a1389a6fee5d50b74945 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
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
/* print the fractions of denominator <= n between n1/d1 and n2/d2 */ | |
void genfrac(int n, int n1, int d1, int n2, int d2) { | |
if (d1 + d2 > n) return; | |
genfrac(n, n1, d1, n1 + n2, d1 + d2); | |
cout << n1 + n2 << "/" << d1 + d2 << "\n"; | |
genfrac(n, n1 + n2, d1 + d2, n2, d2); | |
} | |
int main() { | |
int n = 5; | |
cout << "0/1\n"; | |
genfrac(n, 0, 1, 1, 1); | |
cout << "1/1\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment