fork download
  1. #include <stdio.h>
  2.  
  3. int maze(int n,int m){
  4. int downways=0;
  5. int rightways=0;
  6. if(n==1 && m==1) return 1;
  7. if(n==1){//only rightways
  8. rightways+=maze(n,m-1);
  9. }
  10. if( m==1){// only downways
  11. downways+=maze(n-1,m);
  12. }
  13. if(n>1 && m>1){
  14. rightways+=maze(n,m-1);
  15. downways+=maze(n-1,m);
  16. }
  17. int totalways= rightways+ downways;
  18. return totalways;
  19. }
  20. int main(void) {
  21. int n;
  22. printf("Enter the rows: \n");
  23. scanf("%d",&n);
  24. int m;
  25. printf("Enter the columns: \n");
  26. scanf("%d",&m);
  27. int ways = maze(n,m);
  28. printf(" answer is %d",ways);
  29. return 0;
  30. }
Success #stdin #stdout 0s 5324KB
stdin
3
3
stdout
Enter the rows: 
Enter the columns: 
 answer is 6