Classes C+ Program Armstrong number of n digits
Write a program in C+ to check Armstrong’s number of n digits using classes and objects in object-oriented programming.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include<iostream> #include<math.h> using namespace std; class T4Tutorials { protected: int n1,num,result=0,r; int n=0; public: int function() { cout<<"check wether the number is armstromg or not :"<<endl; cin>>n; num=n1; while(num!=0) { num/=10; n++; } num=n1
; while(num !=0) { r=num%10; result+=pow(r , n); num /=10; } if(result==n1) cout<<"is an armstrong number :"<<endl; else cout<<" is not an armstrong number :"<<endl; } }; int main() { T4Tutorials obj; obj.function(); } |
Output
check whether the number is Armstrong or not :
6 is not an Armstrong number :