/** * @title: hw4.cpp * @date: 2004.10.28 - 21:25 * @author: vinnie * @source for hw4.exe */ #include #include #include #include #include long double fact( long double x) { if ( x > 0) return x * fact(x-1); return 1; } void main( ) { int iNVars, iConstSum; char strNVars[10], strConstSum[10]; char c; // code system("color 1f"); // menu' label MYMENU: // begin // reset vars iNVars = 0; iConstSum = 0; memset( strNVars, '\0', 10); memset( strConstSum, '\0', 10); // print intro & menu system("cls"); printf("\t\t SLCC - CS 2310-01 - Fall '04 - HW4\n"); printf("\n Given a equation with n nonnegative integers,"); printf("\n whose sum is k, list all the solutions.\n"); printf("\n Please input how many variables : "); gets( strNVars); iNVars = atoi( strNVars); printf(" Please input the constant sum : "); gets( strConstSum); iConstSum = atoi( strConstSum); ////////////////////////////////////////////////////////////// int den = iNVars + iConstSum - 1; long double res = fact( den) / ( fact( iConstSum) * fact( iNVars - 1)); printf("\n %Le solutions\n", res); ////////////////////////////////////////////////////////////// // ask for an other trip printf("\n Another one [Y/y/N/n]? "); while ( !kbhit() ); c = getchar( ); if ( c == 'Y' || c == 'y' ) goto MYMENU; ////////////////////////////////////////////////////////////// printf("\n Thanks for using HW4\n"); printf(" Vincenzo Maggio Code - released under GPL\n"); system("color 0f"); }