Friday, March 2, 2012

Armstrong Number

/* A program to check whether a number is armstrong or not*/
// An armstrong number is such that sum of cube of its digit is same number
// e.g. 153 = 1^3 +5^3 +3^3

     #include<stdio.h>
     #include<conio.h>
     #include<math.h>
      main()
      {
     int a,b,c,d,x;
     printf("enter a 3 digit number:" );
     scanf("%d",&x);
     a=x%10;
     b=(x/10)%10;
     c=(x/100)%10;
     d=pow(a,3)+pow(b,3)+pow(c,3);
     if (d==x)
     {printf("armstrong");
     }
     else{printf("not armstrong");}
     getch();
     }


No comments:

Post a Comment