1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <iomanip>
#include <iostream>
using namespace std;
int grid(int low,int left, int right, int bottom)
{
if(low>bottom)
return 0;
if(left>right)
return 0;
if(low == 0 || left== 0)
return 1;
else
return grid(low-1,left,right,bottom)+grid(low,left-1,right,bottom);
}
int main()
{
int startrow,startcol,endrow,endcol,numrow,numcol,topd,rightd,leftd,bottomd;
startrow=0;
startcol=0;
cout<<"Enter the dimentions of your grid starting with the top."<<endl;
cin>>topd;
cout<<"Now enter the right dimention(your right must be less then your left)"<<endl;
cin>>rightd;
cout<<"Now the left"<<endl;
cin>>leftd;
cout<<"Now the bottom(your bottom must be greater then your top)"<<endl;
cin>>bottomd;
cout<<"You are starting at the top left corner(0,0)"<<endl;
//cout<<"Enter the ending coordinates(row and colum): "<<endl;
endrow=bottomd;
endcol=rightd;
numrow=endrow-startrow;
numcol=endcol-startcol;
if(numrow < 0 || numcol <0)
cout<<"There are no possible paths "<<endl;
else
cout<<"There are "<<grid(numrow,numcol,rightd,bottomd)<<" paths"<<endl;
}
|