Armstrong number


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,temp,sum=0,d=0;
cout<<"enter the number";
cin>>a;
temp=a;
while(a)
{
d=a%10;
sum=sum+(d*d*d);
a=a/10;
}
if(sum==temp)
{
cout<<"The no.is armstrong";
}
else
{
cout<<"The no.is not armstrong";
}
getch();
}
******output*******
enter the number153
The no.is armstrong    

Algorithm:
1. Start
2. Read A
3. Set temp=A
4. Check while (A)
    if true:
    a)Set D=A%10
    b)Set sum=sum + (D*D*D)
    c)Set A=A/10
    [end of while structure]
5. Check if sum = temp
    a) Write: The no. is amstrong
6. else
    a) Write: The no. not is amstrong 
    [end of if else structure]  
7. Stop                                                        
                                                                             

0 comments:

Post a Comment