Armstrong Using Class .cpp

Kali26 · September 23, 2020 · C++
#include <iostream>
using namespace std;
class number
{
    int n,s,t,r;
    public:
    void getdata();
    void ascompute();
};
void number::getdata()
{
    cout<<"\n Enter a number:";
    cin>>n;
}
void number::ascompute()
{
    t=n;
    s=0;
    while (n!=0)
    {
        r=n%10;
        s+=r*r*r;
        n=n/10;
    }
    if(s==t)
    cout<<"\n The given number is a Armstrong number";
    else
    cout<<"\n The given number is a not a Armstrong number";
}
int main() 
{
    number n;
    cout<<"\n CHECKING OF ARMSTRONG  OR NOT";
    cout<<"\n -----------------------------";
    n.getdata();

   n.ascompute();
    
    return 0;
}

Comments

Please sign up or log in to contribute to the discussion.