fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void printCombs(const char* prefix, int n) {
  5. int i, j, limit = ceil(sqrt(n));
  6. for(i = 1; i < limit; i++) {
  7. for(j = i; j < limit; j++) {
  8. if(i*i + j*j == n) {
  9. printf("%s%d,%d\n", prefix, i, j);
  10. char buffer[1024];
  11. sprintf(buffer, "%s%d,", prefix, j);
  12. printCombs(buffer, i*i);
  13. sprintf(buffer, "%s%d,", prefix, i);
  14. printCombs(buffer, j*j);
  15. }
  16. }
  17. }
  18. }
  19.  
  20. int main() {
  21. printCombs("", 1000);
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
10,30
30,6,8
10,18,24
18,26
18,10,24
18,24,6,8