Problem using tgamma() function

tgamma() function shows different result for same logic. Code are given below..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    int n;

    while(cin>>n)
    {
        int fact = tgamma(n+1);
        cout<<fact<<endl;
    }

    return 0;


Input: 6
Output: 719


But when i write as following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    int n;

    while(cin>>n)
    {
        cout<<tgamma(n+1)<<endl;
    }

    return 0;


Input: 6
Output: 720

Why the difference? What happens here?
tgamma returns a double

so the first one casts it to an int, the second one doesn't
Topic archived. No new replies allowed.