Concept of Armstrong in C++
#include<iostream.h>
#include<conio.h>
void main()
{
int n,rem,sum=0,temp;
cout<<"Enter a number:";
cin>>n;
temp=n;
while(n>0)
{
rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(temp==sum)
cout<<"Entered number is a armstrong";
else
cout<<"Entered number is not armstrong";
getch();
}
output
#include<iostream.h>
#include<conio.h>
void main()
{
int n,rem,sum=0,temp;
cout<<"Enter a number:";
cin>>n;
temp=n;
while(n>0)
{
rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(temp==sum)
cout<<"Entered number is a armstrong";
else
cout<<"Entered number is not armstrong";
getch();
}
output
No comments:
Post a Comment