By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,381 Members | 1,573 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,381 IT Pros & Developers. It's quick & easy.

mathematic calculation

P: 1
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
Nov 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: 51
hi:
your program have sevral problems,incluging :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.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. long no,x;
  6.  
  7. clrscr();
  8. printf("Enter numbor : ");
  9. scanf("%ld",&no);
  10. x=no*3000;
  11. printf("%ld",x);
  12. getch();
  13. }
Nov 10 '06 #2

Expert 100+
P: 1,510
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#limits.h

the following program will print out useful information from <limits.h>
Expand|Select|Wrap|Line Numbers
  1.  /* Program 9_2, display integral sizes and ranges */
  2.  
  3. #include <stdio.h>
  4. #include <limits.h>
  5.  
  6. int main(void)
  7. {
  8.     printf("\nchar               size %2d bytes, range %11d to %11d ",
  9.                  (int) sizeof(char), CHAR_MIN, CHAR_MAX);
  10.     printf("\nsigned char        size %2d bytes, range %11d to %11d ",
  11.                  (int) sizeof(signed char), SCHAR_MIN, SCHAR_MAX);
  12.     printf("\nunsigned char      size %2d bytes, range %11d to %11d ",
  13.                  (int) sizeof(unsigned char), 0, UCHAR_MAX);
  14.     printf("\nshort int          size %2d bytes, range %11d to %11d ",
  15.                  (int) sizeof(short int), SHRT_MIN, SHRT_MAX);
  16.     printf("\nunsigned short int size %2d bytes, range %11u to %11u ",
  17.                  (int) sizeof(unsigned short int), 0, USHRT_MAX);
  18.     printf("\nint                size %2d bytes, range %11d to %11d ",
  19.                  (int) sizeof(int), INT_MIN, INT_MAX);
  20.     printf("\nunsigned int       size %2d bytes, range %11u to %11u ",
  21.                  (int) sizeof(unsigned int), 0, UINT_MAX);
  22.     printf("\nlong int           size %2d bytes, range %11ld to %11ld ",
  23.                  (int) sizeof(long int), LONG_MIN, LONG_MAX);
  24.     printf("\nunsigned long int  size %2d bytes, range %11lu to %11lu ",
  25.                  (int) sizeof(unsigned long int), 0L, ULONG_MAX);
  26.     return 0;             
  27. }
  28.  
for example Turbo C V3.01 uses 16-bit to store an int
Expand|Select|Wrap|Line Numbers
  1. char               size  1 bytes, range        -128 to         127 
  2. signed char        size  1 bytes, range        -128 to         127 
  3. unsigned char      size  1 bytes, range           0 to         255 
  4. short int          size  2 bytes, range      -32768 to       32767 
  5. unsigned short int size  2 bytes, range           0 to       65535 
  6. int                size  2 bytes, range      -32768 to       32767 
  7. unsigned int       size  2 bytes, range           0 to       65535 
  8. long int           size  4 bytes, range -2147483648 to  2147483647 
  9. unsigned long int  size  4 bytes, range           0 to  4294967295 
  10.  
The GNU gcc compiler on the same machine uses 32-bits
Expand|Select|Wrap|Line Numbers
  1. char               size  1 bytes, range        -128 to         127 
  2. signed char        size  1 bytes, range        -128 to         127 
  3. unsigned char      size  1 bytes, range           0 to         255 
  4. short int          size  2 bytes, range      -32768 to       32767 
  5. unsigned short int size  2 bytes, range           0 to       65535 
  6. int                size  4 bytes, range -2147483648 to  2147483647 
  7. unsigned int       size  4 bytes, range           0 to  4294967295 
  8. long int           size  4 bytes, range -2147483648 to  2147483647 
  9. unsigned long int  size  4 bytes, range           0 to  4294967295
  10.  
Nov 10 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.