//code
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
main()
{
int num,rem,j=1,k=1,count=0,sum=0;
printf("Enter no\n");
scanf("%d",&num);
int copy=num;
while(num>0)
{
num=num/10;
count=count+1;
}
num=copy;
for(int i=0;i<count;i++)
{
rem=num%10;
while(j<=count)
{
k=k*rem;
j++;
}
//Instead of loop i can directly use pow(); function to get power
//k=pow(rem,count);
sum=sum+k;
j=1;
k=1;
num=num/10;
}
if(sum==copy)
{
printf("Armstrong no\n");
}
else
{
printf("Not an armstrong no\n");
}
}
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
main()
{
int num,rem,j=1,k=1,count=0,sum=0;
printf("Enter no\n");
scanf("%d",&num);
int copy=num;
while(num>0)
{
num=num/10;
count=count+1;
}
num=copy;
for(int i=0;i<count;i++)
{
rem=num%10;
while(j<=count)
{
k=k*rem;
j++;
}
//Instead of loop i can directly use pow(); function to get power
//k=pow(rem,count);
sum=sum+k;
j=1;
k=1;
num=num/10;
}
if(sum==copy)
{
printf("Armstrong no\n");
}
else
{
printf("Not an armstrong no\n");
}
}