/* http://www.mrwadlo.com */ #include #include int m_size[3]; double fact( double num ); int main() { int xp, yp, zp; double x,y,z; clrscr(); printf("\nWelcome to the cubic calculator. This program can determine the number of\n"); printf("possible combinations of path leading from one third-dimension location to\n"); printf("another. The start point is assumed to be at the origin (0,0,0). The end point\n"); printf("is located at a specified location with integer axis values. Each move is one\n"); printf("unit in the direction of either X, Y, or Z (diagonal moves prohibited).\n\n"); printf("Enter X Axis Vertex Count (unit length): "); scanf("%d", &xp ); printf("Enter Y Axis Vertex Count (unit length): "); scanf("%d", &yp ); printf("Enter Z Axis Vertex Count (unit length): "); scanf("%d", &zp ); if ( xp+yp+zp > 173 ) { printf("\nError may result when x+y+z > 173. Press any key to continue.\n"); getch(); } x = (double)xp; y = (double)yp; z = (double)zp; printf("\nPlotting paths from (0,0,0) to (%G,%G,%G)...\n",x,y,z); printf("\nSolution: %.18G\n", fact( x + y + z - 3 ) / ( fact( x - 1) * fact( y - 1) * fact( z - 1) )); getch(); return 0; } double fact( double num ) { double val = num - 1; while ( val > 1 ) { num *= val; val--; } if ( num == 0 ) return 1; return num; }