#include
using namespace std;
int power(int, int);
int main() {
int armstrong=0,remainder=0,num=0,result=0,check,number;
cout<<"Enter Number to find it is an Armstrong number?";
cin>>num;
check=num;
number=num;
int digits = 0;
if (number < 0) {
digits = 1;
}
while (number) {
number /= 10;
digits++;
}
for(int i=1;num!=0;i++){
remainder=num%10;
num=num/10;
armstrong=armstrong+power(remainder,digits);
}
if(armstrong==check) {
cout< } else {
cout< }
return 0;
}
int power(int remainderVal, int digit) {
int i, multiplyVal = 1;
for (i = 1; i <= digit; i++)
multiplyVal = multiplyVal*remainderVal;
return multiplyVal;
}
using namespace std;
int power(int, int);
int main() {
int armstrong=0,remainder=0,num=0,result=0,check,number;
cout<<"Enter Number to find it is an Armstrong number?";
cin>>num;
check=num;
number=num;
int digits = 0;
if (number < 0) {
digits = 1;
}
while (number) {
number /= 10;
digits++;
}
for(int i=1;num!=0;i++){
remainder=num%10;
num=num/10;
armstrong=armstrong+power(remainder,digits);
}
if(armstrong==check) {
cout<
cout<
return 0;
}
int power(int remainderVal, int digit) {
int i, multiplyVal = 1;
for (i = 1; i <= digit; i++)
multiplyVal = multiplyVal*remainderVal;
return multiplyVal;
}
No comments:
Post a Comment