C++ DEVELOPER SITE
PYTHONPHP7JAVA
 

Checking Armstrong Number C++ Tutorial


Following is the program to check whether a number is armstrong or not.
#include<iostream.h&ht;
void main()
{
    int no, ld, nn=0, cn;
    cout<<"Enter a number to be checked : "
    cin>>no;
    cn==no;
    while(no > 0)
    {
        ld=no%10;
        nn=nn+ld*ld*ld;
        no=n/10;
    }
    if(nn==cn)
    {
        cout<<"\n"<<cn<<" is an armstrong number";
    }
    else
    {
        cout<<"\n"<<cn<<" is not an armstrong number";
    }
}

Output

Enter a number to be checked : 153
153 is an armstrong number