why this is happening with pow function 10^x function

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

I expect your system's signed int values cannot hold the number 10,000,000,000

http://en.wikipedia.org/wiki/Integer_overflow
Yes, moschops is right! try long long
Last edited on
int type holds up to 32627, you need a long type.
No, short holds to 32627, while int holds up to 2147483647! And, long long can hold over 10^20!
Last edited on
How much the different types can hold is implementation defined.
Isn't it based on the bit count?
Topic archived. No new replies allowed.