Thread: how to print big amount of number?

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    4

    how to print big amount of number?

    Hi im new to the forum and a newbie in C programming too

    I need to ask how can i print large amount of number for example,



    Code:
    #include<stdlib.h>
    #include<stdio.h>
    #include<conio.h>d
    #include<math.h>
    #include<limits.h>  /* lol i tried so many header files already. believe me :S */
    
    int main(void)
    
    {
    int apple,mango,result;
    
    apple = 36000;
    mango = 2;
    
    result = apple*mango;
    
    printf ("result : %d\n",result);
    
    return 0;
    }

    the result should be printed out as '72000'.. but what I'd been getting is '6464'.. I tried googling but i couldn't find the solution. which is strange. I heard about integer could only bear numbers from -36000+ up to 36000+ (sorry if i'm wrong).

    anyone can help me fix my code? i really need your kind help Thanks

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Are you using the Turbo-C compiler?
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    On your machine, an int may be 16 bits, limiting it to -32768 to 32767. Try it with longs instead of ints:

    long apple = 36000, mango = 2;
    printf("%l\n", apple * mango);

  4. #4
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Are you working with a 16 bit processor? Integers on most machines nowadays are between +-2 billion or so. I think specifying you data type to long should force it to use a 4 bytes.

    IE: long apple,mango,result;

    See This

  5. #5
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Well, 1 byte variable offers 2^8 numbers. 2 bytes 2^16 and so on. Or less for signed variables

    Try doing this and tell us the results. It will so you how many bytes an int has
    Code:
    printf("Int size = %d\n", sizeof(int)");

  6. #6
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    as far as the headers go, I think you only need stdio.h

  7. #7
    Registered User
    Join Date
    Oct 2009
    Posts
    4
    how thanks for the response.

    bithub: yea i'm using TurboCPP program.

    Epy: i tried using your suggestion
    Code:
    long apple = 36000, mango = 2;
    printf("%l\n", apple * mango);
    it just prints out %l
    Code:
    %l
    C_ntua: i believe you mean printf("Int size = %d\n", sizeof(int)); without the extra ". I run it and it says Int size = 2. does that mean int can only bear up to 65536? (2^16 = 65536). so how can i reach 72000 or higher?


    I really appreciate the help but I still can't get it right. maybe I misunderstood some part of your feedback. Please let me know where I done wrong
    Last edited by zzatan; 10-02-2009 at 11:32 AM.

  8. #8
    Registered User
    Join Date
    Oct 2009
    Posts
    4
    here it comes again..

    Code:
    int X = 36000;
    long L;
    
    L = X*2;
    
    printf ("L = %lu\n",L);

    like i said before, it gives me L = 6464 rather than the correct one, L = 72000 :'( where did i do wrong?

  9. #9
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    signed values have a limit of one less than their bits, so 2^15. Stop using int for god's sake.

    long X = 36000, L = X * 2;
    printf("L = %ld\n", L);

    %ld specifies long, %lu specifies unsigned long.

  10. #10
    Registered User
    Join Date
    Oct 2009
    Posts
    4
    sorry guys my bad for being such a n00b :/

    I GOT IT SOLVED NOW! i replaced all '%d' with '%ld'.. & replace all 'int' to 'long' thank you so much for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why error while the number is very big ?
    By zcrself in forum C Programming
    Replies: 7
    Last Post: 08-31-2009, 06:55 AM
  2. How can I print the number of elements in this array?
    By steals10304 in forum C Programming
    Replies: 13
    Last Post: 08-18-2009, 08:41 PM
  3. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 09:27 AM
  4. Replies: 10
    Last Post: 07-13-2003, 01:48 PM
  5. I need help badly
    By taz_jiggy in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2002, 09:36 PM