Thread: store vaue which is more than 25 digits

  1. #1
    Registered User
    Join Date
    Apr 2006

    store vaue which is more than 25 digits

    hello i am just starting in cpp
    i am trying to find factorial of 99
    i used unsigned long to store it but it shows the result as zero can any one tell me what sort of data type i should use to get the proper result
    thanz in advance

  2. #2
    #define WORLD "sad place" LinuxCoder's Avatar
    Join Date
    Mar 2006
    Try using floats or doubles. They behave quite differently from ints since they are floating point datatypes but i think it's the easiest way to accomplish what you are trying to

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Mar 2006
    99! has 156 digits:

    And I don't know of any datatype able to store THAT many.

    It comes out as zero because unsigned long on a 32-bit machine is 4294967296 and 99! % 4294967296 == 0

    99! == 4294967296 (ie 2 ^ 32) *

    Even on a 64-bit machine:
    99! == 18446744073709551616 (ie 2 ^ 64) *

    Option #1: Use double, but forego accuracy.
    Option #2: Use a bignum library like GMP or Apfloat.
    Option #3: Accept the fact that n! for n > 33 will always return 0
    #include <stdio.h>
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Not returning correct results
    By drty2 in forum C Programming
    Replies: 4
    Last Post: 01-19-2009, 12:39 PM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. Free Store of memory
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2007, 02:27 PM
  4. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 06:16 AM
  5. magic square
    By dizzyhippy in forum C Programming
    Replies: 1
    Last Post: 03-11-2002, 12:36 PM