mathematic calculation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • latufi
    New Member
    • Nov 2006
    • 1

    #1

    mathematic calculation

    Hi friends,,

    I'm new in c programming
    need your help,,
    I just do a simple mathematics calculation

    #include<stdio. h>
    void main()
    {
    int no,x;
    clrscr();

    printf("Enter numbor : ");
    scanf("%d", &no);

    x=no*3000;
    printf("%d", x);
    getch();
    }

    if I put 30, the output that I will get is 44464.. should be 90000,
    can someone help me..

    thanks
  • khajeddin
    New Member
    • Nov 2006
    • 51

    #2
    hi:
    your program have sevral problems,inclug ing :speling and errors.
    well, you have to pay attention to the capacity of "int".as you have to know that you're allowed to put numbers from " -32768 to 32767 "in the" int variables" ,even you use the "unsinged int variables" you're allowed to put numbers less than 65536 in it.
    so what u have to do is to chang the type of variables to "long int" or "long"that have capacity about " 0 to 4294967296 ",and please correct your speling too.and olso we don't have getch() and clrscr() in<stdio.h> you should add <conio.h> too the libraries.

    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    long no,x;
    
    clrscr();
    printf("Enter numbor : ");
    scanf("%ld",&no);
    x=no*3000;
    printf("%ld",x);
    getch();
    }

    Comment

    • horace1
      Recognized Expert Top Contributor
      • Nov 2006
      • 1510

      #3
      the maximum numeric range an int can hold is compiler and system dependent and you can determine these from the header file <limits.h>, see
      http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html#li mits.h

      the following program will print out useful information from <limits.h>
      Code:
       /* Program 9_2, display integral sizes and ranges */
      
      #include <stdio.h>
      #include <limits.h>
      
      int main(void)
      {
          printf("\nchar               size %2d bytes, range %11d to %11d ",
                       (int) sizeof(char), CHAR_MIN, CHAR_MAX);
          printf("\nsigned char        size %2d bytes, range %11d to %11d ",
                       (int) sizeof(signed char), SCHAR_MIN, SCHAR_MAX);
          printf("\nunsigned char      size %2d bytes, range %11d to %11d ",
                       (int) sizeof(unsigned char), 0, UCHAR_MAX);
          printf("\nshort int          size %2d bytes, range %11d to %11d ",
                       (int) sizeof(short int), SHRT_MIN, SHRT_MAX);
          printf("\nunsigned short int size %2d bytes, range %11u to %11u ",
                       (int) sizeof(unsigned short int), 0, USHRT_MAX);
          printf("\nint                size %2d bytes, range %11d to %11d ",
                       (int) sizeof(int), INT_MIN, INT_MAX);
          printf("\nunsigned int       size %2d bytes, range %11u to %11u ",
                       (int) sizeof(unsigned int), 0, UINT_MAX);
          printf("\nlong int           size %2d bytes, range %11ld to %11ld ",
                       (int) sizeof(long int), LONG_MIN, LONG_MAX);
          printf("\nunsigned long int  size %2d bytes, range %11lu to %11lu ",
                       (int) sizeof(unsigned long int), 0L, ULONG_MAX);
          return 0;             
      }
      for example Turbo C V3.01 uses 16-bit to store an int
      Code:
      char               size  1 bytes, range        -128 to         127 
      signed char        size  1 bytes, range        -128 to         127 
      unsigned char      size  1 bytes, range           0 to         255 
      short int          size  2 bytes, range      -32768 to       32767 
      unsigned short int size  2 bytes, range           0 to       65535 
      int                size  2 bytes, range      -32768 to       32767 
      unsigned int       size  2 bytes, range           0 to       65535 
      long int           size  4 bytes, range -2147483648 to  2147483647 
      unsigned long int  size  4 bytes, range           0 to  4294967295
      The GNU gcc compiler on the same machine uses 32-bits
      Code:
      char               size  1 bytes, range        -128 to         127 
      signed char        size  1 bytes, range        -128 to         127 
      unsigned char      size  1 bytes, range           0 to         255 
      short int          size  2 bytes, range      -32768 to       32767 
      unsigned short int size  2 bytes, range           0 to       65535 
      int                size  4 bytes, range -2147483648 to  2147483647 
      unsigned int       size  4 bytes, range           0 to  4294967295 
      long int           size  4 bytes, range -2147483648 to  2147483647 
      unsigned long int  size  4 bytes, range           0 to  4294967295

      Comment

      Working...