Wednesday, September 14, 2011

Program: WAP To Check A Number is Armstrong or Not




Armstrong number:
Also known as narcissistic numbers, Armstrong numbers are the sum of their own digits to the power of the number of digits. As that is a slightly brief wording, let me give an example:

153 = 1³ + 5³ + 3³

Now here is the C++ programming to check whether a number is Armstrong or not .

CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
int Number,Temp,b=0;
cout<<endl<<"Enter any number to check";
cin>>Number;
Temp=Number;
int P;
while(Temp>0)
{
 P=Temp%10;
 b=b P*P*P;
 Temp=Temp/10;
}
if(b==Number)
{
 Cout<<endl<<"Armstrong no";
}
else
{
 cout<<"Not an armstrong no";
}
getch();
}
For any Queries related to this Program ,Drop a comment.

Article by
Chief-Editor

He is a tech Enthusiast, an Altruist and calm mentor. He loves to code. He is also a creative graphic designer. Do check out his designfolio @ Jasmeet.asia If you like This post, you can follow me on Twitter.



For Further Reading,
C++ Program, Control Structures, If-Else Statement, While Loop

0 comments:

Post a Comment