//function for factorial
long int multiplyNumbers(int n)
{
    if (n >= 1)
        return n*multiplyNumbers(n-1);
    else
        return 1;
}
int main()
{
    int n;
    printf("Enter a positive integer: ");
    scanf("%d", &n);
    printf("Factorial of %d = %ld", n, multiplyNumbers(n));
    return 0;
}
int multiplyNumbers(int m, int n) {

  if(n==1){
    return m;
}
  int smallAns =multiplyNumbers(m, n-1);
  return m +smallAns;

}
Пример #4
0
int main () {

	printf("I will multiply two numbers for you. \n");
	
	firstNumber();
	secondNumber();
	multiplyNumbers();

	return 0;
}
Пример #5
0
	bignum multiplyNumbers(const bignum &bn1, const bignum &bn2)
	{
		if (bn1.getBase() != bn2.getBase())
			return multiplyNumbers(bn1, bn2.getConverted(bn1.getBase()));

		bignum temp(0);
		temp.setBase(bn1.getBase());

		if (bn1.isZero() || bn2.isZero())
			return temp;

		//multiply bn1 by each digit of bn2 independently, then add the values together
		int counter = bn2.getDigitRange();
		for (int i = 0; i < counter; i++)
		{
			int toMultiply = (ONES_PLACE - bn2.getDecimalCount()) + i;

			//verify function isn't checking beyond bounds of the stored array
			if (toMultiply >= 0)
			{
				if (toMultiply >= MAXDIGITS)
					throw error_handler(__FILE__, __LINE__, "The value being calculated is too large for the settings provided");

				bignum toAdd = multiplyNumbersSimple(bn1.absolute(), bn2.getDigit(toMultiply));

				toAdd.leftShift(i);
				temp += toAdd;
			}
		}

		if (bn1.isNegative() != bn2.isNegative())
			temp.setNegative();

		//adjust for added decimal places during multiplication
		temp.rightShift(bn2.getDecimalCount());

		temp.updateDigits();
		return temp;
	}