Armstrong numbers are the sum of their own digits to the power of the number of digits
For example, 153 = 1³ + 5³ + 3³
Here is my attempt
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int i,r,h,t,o,s,n;
printf("Please enter any integer.(Not more than four-digits) ");
scanf("%d" , &i);
if (i-1000>=0) (n=4);
if (i-1000<0 && i-100>=0) (n=3);
if (i-100<0 && i-10>=0) (n=2);
if (i-10<0 && i-1>=0) (n=1);
r=i/1000;
h=(i-1000*r)/100;
t=(i-1000*r-100*h);
o=(i-1000*r-100*h-10*t);
s=r^n+h^n+t^n+i^n+o^n;
if (i==s) printf("It is an Armstrong number. ");
else printf("It is not an Armstrong number. ");
getch();
}
I understand that
s=r^n+h^n+t^n+i^n+o^n;
is wrong,how do i proceed then ?