Today we are going to write a program in C++ to check a number is Armstrong number or not. Have a look at the definition of an Armstrong number: An Armstrong variety of 3 digits is AN whole number such the add of the cubes of its digits is capable the amount itself. for instance, 371 is AN Armstrong variety since 3**3 + 7**3 + 1**3 = 371. It means that an Armstrong Number is a three digit number such that sum of the cubes of all the digits of the number gives the same number.
#include
#include
#include
int main(void)
{
clrscr();
int n,m=0,x,y;
cout<<"Enter any three digit numnber:";
cin>>n;
y=n;
while(n!=0)
{
x=n%10;
m+=pow(x,3);
n=n/10;
}
if(y==m)
cout<<"The number is an Armstrong number";
else
cout<<"The number is not an Armstrong number";
getch();
return 0;
}
Today we are going to write a program in C++ to check a number is Armstrong number or not. Have a look at the definition of an Armstrong number: An Armstrong variety of 3 digits is AN whole number such the add of the cubes of its digits is capable the amount itself. for instance, 371 is AN Armstrong variety since 3**3 + 7**3 + 1**3 = 371. It means that an Armstrong Number is a three digit number such that sum of the cubes of all the digits of the number gives the same number.
#include
#include
#include
int main(void)
{
clrscr();
int n,m=0,x,y;
cout<<"Enter any three digit numnber:";
cin>>n;
y=n;
while(n!=0)
{
x=n%10;
m+=pow(x,3);
n=n/10;
}
if(y==m)
cout<<"The number is an Armstrong number";
else
cout<<"The number is not an Armstrong number";
getch();
return 0;
}
No Comment