On 2/14/07, arun kumar <[EMAIL PROTECTED]> wrote:
>
>
> Hi
> Pls send me program to calculate the factorial of given no.
>

#include <iostream>

template <int N>
struct Factorial
{
    enum { value = N * Factorial<N-1>::value };
};

template <>
struct Factorial<1>
{
    enum { value = 1 };
};

// example use
int main()
{
    const int fact5 = Factorial<15>::value;
    std::cout << fact5 << endl;
    return 0;
}

(From http://aszt.inf.elte.hu/~gsd/halado_cpp/ch06s04.html)

-- 
PJH
Aio, quantitas magna frumentorum est

Reply via email to