Armstrong Program in C++
Hello friends; here we will write code to check given number is Armstrong or not.A positive integer is called an Armstrong number if the sum of cubes of individual digit is equal to that number itself. For example:
153 = 1*1*1 + 5*5*5 + 3*3*3
Example of C++ Program to Check Armstrong Number
#include<iostream.h>
#include<conio.h>
using namespace std;
void main()
{
int armstrong=0,num=0,result=0,check;
cout<<"Enter any Number: ";
cin>>num;
check=num;
for(int i=1;num!=0;i++)
{
armstrong=num%10;
num=num/10;
armstrong=armstrong*armstrong*armstrong;
result=result+armstrong;
}
if(result==check)
{
cout<<check<<" is an Armstrong Number";
}
else
{
cout<<check<<" is NOT an Armstrong Number";
}
getch();
}
Output:
Enter any Number: 153I hope this code is useful for you; For download, this code visit our website, the Website link is already given above.
153 is an Armstrong Number
No comments:
Post a Comment