![]() |
Salt Lake City Monday, 2008.09.08 09:22 MST [GMT-7] |
| Home - IT: IT Security - Programming - OS - HW - SW - Internet - IT News - Technology - Science - Communication - News: World - USA - USA States - Alternative - Business - Investment - more coming soon... | |
/**
* @title: hw4.cpp
* @date: 2004.10.28 - 21:25
* @author: vinnie
* @source for hw4.exe
*/
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
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");
}
Vincenzo Maggio