please help and tell me what is problem in this code which always shows me “false” when number entered.
Always shows false statement
hello @sid_kapoor
after while loop ur no will become zero so u need to update it with n .
check here->
it is still shows wrong answer
check ur updated code hhere->
#include <iostream>
#include <math.h>
using namespace std;
int main()
{ int n;
cin >> n;
int no=n; int digits=0;
int sum=0;
while (no>0) {
digits++;
no=no/10;
}
no=n;// added
while (no>0) {
int rem=no%10; // here u were using n
sum = sum + pow(rem, digits);
no=no/10;
}
if (n==sum) { cout << "true" << endl; }
else { cout << "false" << endl; }
return 0;
}
it still showing same wrong output ,dont know what’s going wrong
yes it is done now thank you so much