Calculation of the path to a certain place

topic

From (0,0) to (m,n), each time you take one step, you can only go up or to the right. How many paths are there to go to (m,n)
Insert picture description here

#include<stdio.h>
#include<stdlib.h>


int numroute(int m,int n)
{
    
    
	int w;
	if ((m == 0) && (n == 0)) w = 0;
	else if ((n == 1&& m == 0) || (m == 1&&n == 0)) w = 1;
	else if (n == 0) w = numroute(m - 1, n);
	else if (m == 0) w = numroute(m, n - 1);
	else {
    
    
		w = numroute(m, n - 1) + numroute(m - 1, n);
	}
	return w;
}

int main() {
    
    
	int m, n, w;
	scanf_s("%d %d", &m, &n);
	w = numroute(m, n);
	printf("the number of route is:%d\n", w);
	return 0;
}

Guess you like

Origin blog.csdn.net/m0_48711099/article/details/113100754