1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How can i use long int in C

Discussion in 'Programming' started by sheelnidhi, Jun 1, 2011.

  1. #1
    Dear Friends,

    When i make a program of factorial in C it runs but it doesn't gives the factorial of big numbers. Like 20 or 50. I read about long int data-type in book, but i am unable to process it. Please help in these regards.
     
    sheelnidhi, Jun 1, 2011 IP
  2. brian65

    brian65 Active Member

    Messages:
    1,172
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #2
    I think you mean long long not long int. long int is equivalent to long I believe. long long will give you a 64-bit integer value, but even this may not be enough to work with larger factorials.
     
    brian65, Jun 2, 2011 IP
  3. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Without a bignum library, you won't be able to do this. C++ just doesn't have the support 'out of the box' for numbers over a certain size. If you're feeling brave, you can code your own. GMP works well, and I'm pretty sure it works with Visual Studio.

    http://gmplib.org/
     
    organicCyborg, Jun 2, 2011 IP
  4. sheelnidhi

    sheelnidhi Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks Brian and organicCyborg, I got my answer. Here it is:-

    void main()
    {
    long int a;
    printf ("Enter the population of India");
    scanf("%ld",&a);

    Thanks all for your support.
     
    sheelnidhi, Jun 4, 2011 IP
  5. infocus1

    infocus1 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    long long int is 64 bits.
    long int is long, thus usually 32 bits.
    %lld should be fine for printf, but you should really look up the format specifications instead of asking. It's easy.
     
    infocus1, Mar 28, 2012 IP
  6. Malatya

    Malatya Active Member

    Messages:
    710
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #6
    you can have a look at double.
     
    Malatya, Mar 30, 2012 IP
  7. Vivianflo

    Vivianflo Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think fot that you should use double variable in it.....instead of long and it is used as int...
     
    Vivianflo, Mar 30, 2012 IP
  8. raspms

    raspms Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I think for that you should use double datatype for that variable..
     
    raspms, Apr 4, 2012 IP