Thread: overflow problem

  1. #1
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159

    Wink overflow problem

    Code:
    int main()
    {
    int i,j=1,n;
    printf("donnez n\n");
    for(i=0;i<n;i++)
    
    {
    
    j*=(n-i);
    
    }
    
    printf("%i!=%i",n,j);
    
    return 0;
    }
    [quote]
    my program has a problem with integers (< =13)

    i need help !!!
    i want a function that calcul factoriel(n) with n >>]0,+00[
    Code:
    --------- no recursion function please---------------
    [\quote ]
    Last edited by enjoy; 10-17-2004 at 04:49 PM. Reason: n...

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    11
    Code:
    int i,j=1,n;
    printf("donnez n\n");
    for(i=0;i<n;i++)
    Your n needs some sort of value.

    If you want to calculate the factorial of j,
    set j as the number you want to factorial.
    and the n = j-1.

    Code:
    int i, j,n;
    
    j = 5; n = j-1;
    
    for (i=n; i>0; i--)
     j*=i;
    Ryan

  3. #3
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    Code:
    sorry about missing
    scanf("%i",&n);
    the problem percist with n==13
    ....!!!

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by enjoy
    Code:
    sorry about missing
    scanf("%i",&n);
    the problem percist with n==13
    ....!!!

    13 Factorial is greater than 2 to the power 32.

    Can't be represented as a 32-bit integer.

    Regards,

    Dave

  5. #5
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    ..... !!!!

  6. #6
    .
    Join Date
    Nov 2003
    Posts
    307
    If your compiler supports it, try using long long variables.

    Generally, if you need to work with huge numbers you need to have a bignum library like GMP from www.gnu.org

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by jim mcnamara
    If your compiler supports it, try using long long variables.

    Generally, if you need to work with huge numbers you need to have a bignum library like GMP from www.gnu.org

    64-bit ints will take you all the way to 20 factorial.

    Regards,

    Dave

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack overflow errors in 3 areas
    By ulillillia in forum C Programming
    Replies: 13
    Last Post: 04-29-2007, 03:20 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM