ish code me false kyo a rha h , ishka correct ans kya h vo bta do
Armstrong number code
@Aarti.com hey apne niche dono conditions me print krate hue true likha tha ,which I have corrected ,also use long long int in case of int :
mene ishko true kr diya h pr ab ye submit nhi ho rha kyo??
@Aarti.com hey apke logic me problem hai actually sum of cubes nhi lena sum of no raise to power n that is no of digits lena hai ,qstn is different from basic armstrong.Please check it again.
@Aarti.com here is pseudo code:
int fastPow(int a, int b)
{
if(b==0)
return a;
int smallAns = fastPow(a, b/2);
smallAns *= smallAns;
if(b & 1)
return smallAns*a;
return smallAns;
}
bool isArmstrong(int n)
{
int noOfDigits = 0;
int m = n;
while (m)
{
noOfDigits++;
m /= 10;
}
m = n;
int sum = 0;
while (m)
{
int r = m % 10;
sum += fastPow(r, noOfDigits);
m /= 10;
}
return n == sum;
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.