Hello!! I was trying to solve the following which is simple enough to understand:
5 - 5 * 5 - 25
6 - 6 * 6 - 36
25 - 25 * 25 - 625
625 - 625 * 625 - 390625 .... So on
See the last digit or digits are equal to the number that we provided after making square of that number. What I've done so far as follows:
int sqr, mod, nn, count = 0, div, num = 625;
nn = num*num;
sqr = nn;
while(nn != 0) //To count total digits
{
nn /= 10;
++count;
}
div = pow(10, count - 1); //Getting the power of 10 for modulo operation
mod = sqr % div;
if(num == mod)
{
return 1;
}
else
{
return 1;
}
Above code works fine up to two digits like 25 * 25 = 625. But when I try to do this 625 * 625 = 390625, it does ...
Go to the complete details ...