C++ program to check whether a given number is an armstrong number or not

#include <iostream>
using namespace std;
void main()
{
 int num,r,sum=0,temp;

    cout<<"Input  a number: ";
    cin>>num;
    for(temp=num;num!=0;num=num/10){
         r=num % 10;
         sum=sum+(r*r*r);
    }
    if(sum==temp)
         cout<<" is an Armstrong number."<<temp<<endl;
    else
         cout<<" is not an Armstrong number."<<temp<<endl;
system ("pause");
}


Test Data :
Input a number: 153
Expected Output :
153 is an Armstrong number.

C++ program to check whether a given number is an armstrong number or not C++ program to check whether a given number is an armstrong number or not Reviewed by Unknown on May 21, 2017 Rating: 5

No comments:

Powered by Blogger.