Essentially I wrote a program to to multiply a number by its own power and iterate it till some value n.
Eg: 1^1, 2^2, 3^3, 4^4, 5^5, so on.
Here's the code :
int n = 20, i ;
long long int fin;
for(i=1;i<=n;i++){
fin = pow(i,i);
cout<<fin<<endl;
}
I realised that I had hit the int-max-range limit by the time the iteration reached to 10.
Later I increased the declaration to 'long long int' and realised I hit a limit once I reached 20.
My question is : Why did the max output spit out as a negative max-range number instead of a positive one?
I'm new to C++ I reckon I might be asking a basic question.
Thank you.
Aucun commentaire:
Enregistrer un commentaire