fork download
  1. #include <stdio.h>
  2.  
  3. int paths(int x, int y) {
  4. if (x == 0 && y == 0) {
  5. return 0;
  6. }
  7. else if (x == 0 || y == 0) {
  8. return 1;
  9. }
  10.  
  11. return paths(x - 1, y) + paths(x, y - 1);
  12. }
  13.  
  14. int main(void) {
  15. int x, y;
  16.  
  17. scanf("%d", &x);
  18. scanf("%d", &y);
  19.  
  20. printf("(0,0)から(%d,%d)までの最短経路数は %d です。\n", x, y, paths(x, y));
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5300KB
stdin
3 4
stdout
(0,0)から(3,4)までの最短経路数は 35 です。