PROGRAM TO FIND ARMSTRONG NUMBER

C, C++, etc Programing examples. Post as many you can. Test the programs and discuss about the output of the programes.
Forum rules
Please Discuss & post only about the programes and its Output

PROGRAM TO FIND ARMSTRONG NUMBER

Postby charulatha » Tue Apr 13, 2010 2:21 pm

To find if the given number is an armstrong number or not

# include <iostream.h>
# include <conio.h>
# include <math.h>
void main ()
{ clrscr();
int a,b=0,sum=0;
long int n;
cout<<"ENter the NO. : ";
cin>>n;
for(;n>0;)
//counts the digits
{ a=n%10;
n=n/10;
b++;
}
for(;n>0;)
{ a=n%10;
sum=sum+pow(a,b);
n=n/10;
}
if(sum==n)
{ cout<<"IT IS AN ARMSTRONG NUMBER...";
getch();
}
else
{ cout<<"IT IS NOT AN ARMSTRONG NUMBER...";
getch();
}
}
Regards,
Charulatha.
User avatar
charulatha
Moderator
 
Posts: 756
Joined: Sat Oct 17, 2009 2:54 pm
membership: Senior Technician of The Institution of Engineers (India)- ST

ad
 

Return to Computer Notes : Some Sample Programs

Who is online

Users browsing this forum: No registered users and 0 guests