why this is happening with pow function 10^x function

Jul 17, 2012 at 8:00am
jegop(10,10) should not looks like that

do u know why?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int jegop(int a, int b){
    if( b ==0) return 1;
	int i;
    int c=0;
    
	c=a;
    
	for( i = 0 ; i < b - 1 ; i++ ){
        
		c = c * a;
        
	}
    
	return c;
    
}

int main (int argc, const char * argv[])
{
    cout << jegop(10,9) << " and " << jegop(10,10) << " and " << jegop(10,7) << endl;
}





1000000000 and 1410065408 and 10000000

Jul 17, 2012 at 8:07am
I expect your system's signed int values cannot hold the number 10,000,000,000

http://en.wikipedia.org/wiki/Integer_overflow
Jul 17, 2012 at 8:57am
Yes, moschops is right! try long long
Last edited on Jul 17, 2012 at 6:56pm
Jul 17, 2012 at 3:31pm
int type holds up to 32627, you need a long type.
Jul 17, 2012 at 6:55pm
No, short holds to 32627, while int holds up to 2147483647! And, long long can hold over 10^20!
Last edited on Jul 17, 2012 at 6:57pm
Jul 17, 2012 at 9:21pm
How much the different types can hold is implementation defined.
Jul 17, 2012 at 9:34pm
Isn't it based on the bit count?
Topic archived. No new replies allowed.