Single inheritance C+ Program Armstrong number of n digits
Write a program in C+ to check Armstrong’s number of n digits using single inheritance 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 38 39 40 41 |
#include<iostream> #include<math.h> using namespace std; class T4Tutorials { protected: int n1,num,result=0,r; int n=0; }; class T4tutorials_child:public T4Tutorials { 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_child obj; obj.function(); } |
Output
check whether the number is Armstrong or not :
7 is not an Armstrong number :