Home

C++/CLI Example: Factorial

 

Introduction

This program calculates the factorial of an integer:

using namespace System;

long Factorial(long number)
{
	long p = 1;

	if( number > 1 )
		for(long i = 2; i <= number; i++)
			p *= i;

	return p;
}

int main()
{
	Console::WriteLine(L"The factorial of 5 is: {0}\n", Factorial(5));

	return 0;
}

 

 

 

Home Copyright © 2007-2012 FunctionX