An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.
For example: 153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.
C++ Program to check number is Armstrong or not.
#include <iostream>
using namespace std;
int main() {
    
    int n, temp, sum=0, r;
    cout<<"Enter Number : ";
    cin>>n;
    temp=n;
    while(n!=0)
    {
        r=n%10;
        sum=sum+r*r*r;
        n/=10;
    }
    if(sum==temp)
        cout<<temp<<" Is Amstrong Number";
    else
        cout<<temp<<" Is Not a Amstrong Number";
    return 0;
}Output :
 
 
No comments:
Post a Comment