My program is not working well

This always gives me false. Why?

hello @yashsharma4304
after second while loop no will become zero.
so store it in some variable.

#include<iostream>
#include<cmath>
using namespace std;
int main() {
	int no;
	cin>>no;                 //The number which we have to test 
	int ord = 0;
	int arm_no = 0;
	int n = no;
	int original_no=no; //added
	while(n != 0){          //loop that calculates the order of number
		n = n/10;
		ord++;
	}
	while(no != 0){         //loop for calculating the value of armstrong number  
		int r = no%10;
		arm_no = arm_no + pow(r,ord);
        no = no/10;
	}
	if(arm_no == original_no){          // if the number is armstrong 
        cout<<"true"<<endl;
	}
	else{                     //if the number is not armstrong.
		cout<<"false"<<endl; 
	}
	return 0;
}

1 Like

Ohh so this was my mistake. Thank you for resolving the issue. :slightly_smiling_face: :slightly_smiling_face: