fork download
  1. #include <stdio.h>
  2.  
  3. int maze(int cr,int cc,int er,int ec){
  4. int downways=0;
  5. int rightways=0;
  6. if(cr==er&&cc==ec) return 1;
  7. if(cr==er){//only rightways
  8. rightways+=maze(cr,cc+1,er,ec);
  9. }
  10. if( cc==ec){// only downways
  11. downways+=maze(cr+1,cc,er,ec);
  12. }
  13. if(cr<er && cc<ec){
  14. rightways+= maze(cr,cc+1,er,ec);
  15. downways += maze(cr+1,cc,er,ec);
  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(1,1,n,m);
  28. printf(" answer is %d",ways);
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5320KB
stdin
3
3
stdout
Enter the rows: 
Enter the columns: 
 answer is 6