1. ## Newbies question about the integer type

Hello engineers

I have a fundamental question and I think it somewhere on the c++ book but I could not find it. Any help would be very appreciates.

Question: I am doing OK for the n! for integer type from 1 to 16. But I have problem when i start to enter 17. What is the problem here. Is this because the integer type?

Here is the program

#include <iostream.h>

int main()

{
int in, out;
out = 1;
cout << "Enter input number \n\n";
cin >> in;

for (int x = 1; x <= in ; x ++)
out = x * out;
cout << "Here are the result" <<out<<endl;

return 0;
} 2. Depending on your system and compiler, an int is a number
that can be stored in 2 or 4 bytes ( 16 or 32bit system ).

2 bytes can hold 65536 different values. By default an int is
signed, so it can hold the values -32768 to +32768. If you add
one to the max value, it will revert to the minimum value.
Likewise, subtracting one from the minimum will result in the value
reverting to the maximum.
You could use an unsigned int, as this would hold values from
0 to 65535 but that won't solve your problem.

With four bytes, it's likewise, just larger. A four-byte int
( as I assume your system uses ) will hold 2^32 =
4.294.967.296 different values... ( -2147483648 to
+2147483648 )... so if your number is larger than that,
you'll need another datatype.

I don't know of any standard datatype around though. 3. using an unsigned _int64 would give you the best results if you're only using positive numbers. If you need something even bigger, then you may have to code a class that strings together a whole bunch of unsigned longs and manipulates them as a single composite value. Popular pages Recent additions 