//code
#include<iostream>
#include<math.h>
using namespace std;
main()
{
int sum,k,r,i,count=0;
for(i=1;i<100000;i++)
{
count=0;
k=i;
int num=i;
sum=0;
while(num>0)
{
num=num/10;
count=count+1;
}
while(k>0)
{
r=k%10;
//if count is 3 then it is r power 3 by using pow function
//if count is 4 then it is r power 4
sum=sum+pow(r,count);
k=k/10;
}
if(sum==i)
{
printf("Armstrong no=%d\n",i);
}
}
}
#include<iostream>
#include<math.h>
using namespace std;
main()
{
int sum,k,r,i,count=0;
for(i=1;i<100000;i++)
{
count=0;
k=i;
int num=i;
sum=0;
while(num>0)
{
num=num/10;
count=count+1;
}
while(k>0)
{
r=k%10;
//if count is 3 then it is r power 3 by using pow function
//if count is 4 then it is r power 4
sum=sum+pow(r,count);
k=k/10;
}
if(sum==i)
{
printf("Armstrong no=%d\n",i);
}
}
}
No comments:
Post a Comment