Friday, 12 February 2016

Armstrong Program in C++

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 

Armstrong Program in C++

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: 153
153 is an Armstrong Number
I hope this code is useful for you; For download, this code visit our website, the Website link is already given above.

No comments:

Post a Comment