遞迴_From One Corner to Another

 avatar
user_3763047219
c_cpp
2 years ago
382 B
0
Indexable
Never
#include <stdio.h>

int step(int r, int c) {
	while (r >= 0 && c >= 0) {
		if (r == 0 && c == 0) {
			return 0;
		}
		else if (r!=0 && c == 0) {
			return 1;
		}
		else if (r == 0 && c != 0) {
			return 1;
		}
		else {
			return step(r - 1, c) + step(r, c - 1);
		}
	}
}
int main() {
	int r = 0, c = 0;
	scanf("%d %d", &r, &c);
	printf("%d", step(r-1, c-1));
}