DEV Community

Discussion on: Daily Challenge #183 - Automorphic Numbers

Collapse
 
divyanshpratap profile image
divyansh-pratap • Edited

include

int main()
{
int a , b , q , s=0 ,i=0 , r;
printf("enter the number");
scanf("%d" , &a);
b=a*a;
q=a;

// calculating number of digits in a //

while(q!=0)
{
q=q/10;
i++;

}
q=b;

//finding last two digits of b in reverse order //
for(i;i>0;i--)
{
r=q%10;
s=s*10+r;
q=q/10;
}
q=s;
s=0;

//finding digits in correct order //

while(q!=0)
{
    r=q%10;
    s=s*10+r;
    q=q/10;
}

// now comparing with input //

if(s==a)
{
    printf("true\n");
}
else
{
    printf("false");
}
return 0;

}

This is the solution in c.

steps :-
1 . ask for a input.
2 . calculate and store the square in another variable.
3 . calculate the number of digits in the input.
4 . find the last two digit of square number .
5 . compare the last two digit number with the input number and give the result.

If anyone is intrested in c programming please drop a comment. we can grow together .

output :