Armstrong Program in C++
Hello friends, Hitesh is here, today we will discuss about how to write Armstrong Program in C++. It is very simple and easy to write. Some Armstrong number is 153, it is sum of cube of 1 , 5 and 3.
#include<iostream.h>
#include<conio.h>
int main()
{
int arm=0,n=0,k=0,check;
cout<<"Enter any Number:";
cin>>n;
check=n;
for(int i=1;n!=0;i++){
arm=n%10;
n=n/10;
arm=arm*arm*arm;
k=k+arm;
}
if(k==check){
cout<<check<<"Armstrong Number";
}
else{
cout<<check<<" Not Armstrong Number";
}
return 0;
}
Output:
Enter any Number: 153
Armstrong Number
No comments:
Post a Comment