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()


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);



if (i==s) printf("It is an Armstrong number. ");
else printf("It is not an Armstrong number. ");



I understand that


is wrong,how do i proceed then ?

Line 14 - 17 what????

Have you not heard of else if

if (i >= 1000)
    n = 4;
else if (i >= 100)
    n = 3;

Line 19 - 22 what ???
Have you not heard of the modulus operator %
Line 21 (which is wrong anyway) t=(i%100)/10; Line 25
^ is the xor operator. There is no power operator in C, the is a pow function in the math library. However it uses the double type so will introduce inherent tolerance errors preventing accurate use of the operator == so you may need to write your own version using int/long.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.