C++ OOP program to check Armstrong’s number of n digits with comments.
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 |
//program in C+ to check Armstrong's number of n digits //simple program #include<iostream> //start #include<math.h> //dictionary using namespace std; //libraries class T4Tutorials; //creating class { protected: //declaring private variables int n1,num,result=0,r; //int type variable int n=0; //int type variables public: //data use in anywhere in this programme int function() //create function { cout<<"check weajther the number is armstromg or not :"<<endl; //use for user to enter value cin>>n; //print num value int num=n1; //int type variables while(num!=0) //loop where num is equal to 0 { num/=10; assign num value in which num is divided by and equal to 10 n++; //for increment } num=n1; //num is equal to n1 while(num !=0) //loop where num is equal to 0 { r=num%10; //r is assigning to num modules 10 result+=pow(r , n); //assigning result to pow(r , n) and also added in pow(r ,n) num /=10; //num is divided to 10 } if(result==n1) //condition applied weather the number is armstrong or not cout<<"is an armstrong number :"<<endl; //displaying number else cout<<" is not an armstrong number :"<<endl;//displaying number } }; int main() //main function { T4Tutorials obj;//creating obj variable obj.function();//obj function showed on screen } |