// illustrate the concept of armstrong number in c++
/*
Armstrong number means a number which equals to the sum of cubes of its digits.
Example - 153 (1*1*1 + 5*5*5 +3*3*3)
*/
#include<iostream.h>
#include<conio.h>
void main()
{
int n,rem,sum=0,temp;
cout<<"Enter a number:";
cin>>n;
temp=n;
while(n>0)
{
rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(temp==sum)
cout<<"Entered number is a armstrong";
else
cout<<"Entered number is not armstrong";
getch();
}
Output
Enter a number : 153
Entered number is a armstrong
Enter a number : 165
Entered number is not armstrong
/*
Armstrong number means a number which equals to the sum of cubes of its digits.
Example - 153 (1*1*1 + 5*5*5 +3*3*3)
*/
#include<iostream.h>
#include<conio.h>
void main()
{
int n,rem,sum=0,temp;
cout<<"Enter a number:";
cin>>n;
temp=n;
while(n>0)
{
rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(temp==sum)
cout<<"Entered number is a armstrong";
else
cout<<"Entered number is not armstrong";
getch();
}
Output
Enter a number : 153
Entered number is a armstrong
Enter a number : 165
Entered number is not armstrong
No comments:
Post a Comment