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, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
Source code:
#include <iostream>
using namespace std;
int main()
{
int n, n1, rem, num=0;
cout<<"Enter a positive integer: ";
cin>>n;
n1 = n;
while(n1!=0)
{
rem=n1%10;
num+=rem*rem*rem;
n1/=10;
}
if(num==n)
{
cout << n << " is an Armstrong number.";
}
else
{
cout << n << " is not an Armstrong number.";
}
return 0;
}
Source code:
#include <iostream>
using namespace std;
int main()
{
int n, n1, rem, num=0;
cout<<"Enter a positive integer: ";
cin>>n;
n1 = n;
while(n1!=0)
{
rem=n1%10;
num+=rem*rem*rem;
n1/=10;
}
if(num==n)
{
cout << n << " is an Armstrong number.";
}
else
{
cout << n << " is not an Armstrong number.";
}
return 0;
}
No comments:
Post a Comment